#!/usr/bin/perl $dir = shift || '.'; my $latest = (sort {$b->{mtime} <=> $a->{mtime}} map {{mtime => -M $_, file => $_}} <$dir/*>)[-1]; print $latest->{file}, "\n"; #Using map allows -M to be performed on each file only once #per sort iteration. #once will save a lot of CPU time.