Thanks Rob and Martin for your inputs. I found a solution to my problem. I'm posting it here for whoever might need it. I'm sure there's a faster solution out there but this will do just fine. I had to put the files in an array. :( The reason is that you cannot sort a scalar [ or scalar context such as reading a dir using while (<MYDIR>) ] , it has to be an array.
use strict; use warnings; my $path = "/home/icarus/files"; my $time_var = "-M"; opendir (MYDIR, $path) or die $!; #from older to newest. If you want from newest to oldest, switch the $b for $a then <=> $a for $b my @files = sort { eval($time_var.' "$path/$b" <=> '.$time_var.' "$path/$a"') } grep { -f "$path/$_" } readdir(MYDIR); my @sorted = @files; closedir(MYDIR); foreach (@sorted){ sleep 5; #just to have time to compare print "$_\n"; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/