use File::stat; ... my %m; @allPictures = sort { ($m{$a} ||= stat($a)->mtime) <=> ($m{$b} ||= stat($b)->mtime) } @allPictures;