in reply to Generate m3u files automatically

You can easily replace `ls` with glob, `basename` with File::Basename and `pwd` with Cwd::getcwd. Then your script would also work elsewhere.

As a note on your coding style, Perl is not the shell, so there is little need to quote parameters when passing them to functions.

chdir( "$dir" );

is better written as

chdir( $dir );

You can use the /i switch to make your regular expressions match case insensitively, so /\.mp3$/i will also match .Mp3.