use warnings; use strict; my %bestLine; while () { my ($line, $month, $day, $year) = /(\d+)\s+(\d{2})(\d{2})(\d{4})/; my $date = "$year$month$day"; $bestLine{$line} = $date if ! exists $bestLine{$line} or $bestLine{$line} < $date; } print join "\n", map {"$_: $bestLine{$_}"} sort keys %bestLine; __DATA__ 13 10102005 13 09152005 13 11052005 200 11012005 200 11152004