foreach my $file (glob("$dir/*")) { next if -M $file < 2; # Do something with this old file }