in reply to read directory

It might be more efficient to call ls, if the number of files in the directory is large. You certainly don't want to call -M from inside a sort, as shmem suggests.

my @files = split /\n/, `ls -1t`; for (@files) { ... }
The -1 modifier forces output to one column, and -t sorts by last time modified.