my $latest; $latest->{mtime} = 0; for (glob '/path/to/logs/*.log' ) { next if -d; my $mtime = (stat)[9]; if ($mtime > $latest->{mtime}){ $latest->{filename} = $_; $latest->{mtime} = $mtime; } } print $latest->{filename}, "\n";