in reply to open, chomp, create AND sort ?

It looks like just a matter of tweaking your sort subroutine. I haven't tested your code on my machine, but it looks like either a Schwartzian Transform or the Orcish Maneuver would work. You don't say what OS you're using, so I don't know that stat would work for you, but that's what I'll use here, as that's all I know of.

Anyway, for an ST, you can presort your list of files with the following:

my @sorted = map { $_->[0]} sort { $b->[1] <=> $a->[1] } map { [ $_, (stat $_)[9] ] } @allfiles;

An Orcish Maneuver would be like the following:

my %h; foreach $file (sort { ($h{$a} ||= (stat $a)[9]) <=> ($h{$b} ||= (stat $b)[9]) } @allfiles) { ...;
There are probably other ways to do this, and I'm not quite sure how efficient either of these would be, but these are the only two that popped into my head. HTH.

--

There are 10 kinds of people -- those that understand binary, and those that don't.