# read data to $input $/ = undef; my $input = ; # set $d to be zero my $d = 0; # assign $input to $_ $_ = $input; # with $_ do the following: # find all regex matches for d+/d+/d4, where d+ is one or more digits and d4 are 4 digits # and with each occurrence check if yyyymmdd is larger then $d # and if so, assign it to $d s/\s(\d+)\/(\d+)\/(\d{4})\s/{$d = 10000*$3+100*$1+$2 if $d < 10000*$3+100*$1+$2}/eg; # print date $d print $d; #data to be read by code above __DATA__ File:tfo.supplement.20120901.done 9/1/2012 3:48:00 AM File:tfo.supplement.20120901.zip 421144 KB 9/1/2012 3:48:00 AM File:tfo.supplement.20120904.done 9/4/2012 3:57:00 AM File:tfo.supplement.20120904.zip 421794 KB 9/4/2012 3:57:00 AM File:tfo.supplement.20120905.done 9/5/2012 3:28:00 AM File:tfo.supplement.20120905.zip 421875 KB 9/5/2012 3:28:00 AM