use POSIX qw/strftime/; # generate a timestamp of 12 hours ago in the same format as the data file $twelve_hours_ago = strftime("%Y-%m-%d/%H:%M:%S",localtime(time-12*3600)); while () { next unless /PASS/; # skip the non-PASS entries my ($date) = /^([^.]+)/; # grab the date up to seconds next unless $date gt $twelve_hours_ago; # process the interesting records. }