How to handle filenames with spaces?

Stop using system() to make a call that can be done with a portable library. Perl has a the File::Copy module, use that instead and you don't have to worry about things like this plus you get much better OS portability.


Your code doesn't add any quotes around the filenames.

Try

"\"$_\""

and

"\"$outfile\""

system is rarely the right answer, use File::Copy;

To concatenate all files:

use File::Copy;
my @in = glob "*.mp3";
my $out = "final.mp3";

open my $outh, ">", $out;
for my $file (@in) {
    next if $file eq $out;
    copy($file, $outh);
}
close $outh;