I had to change the sorting line to look like this: @files=sort `ls -1 /usr/share/mpd/playlists/*.m3u`; For some reason the original way wouldn't work for me.
@files=sort `ls -1 /usr/share/mpd/playlists/*.m3u`;