# see manpage for unpack my $TEMPLATE = 'A20 @28A9'; # read the input log into a hash my %last_time; while () { my ($timestamp, $id) = unpack $TEMPLATE; $last_time{$id} = $timestamp; } # print the output log # I have omitted the header for my $id (sort keys %last_time) { print "$id\t$last_time{$id}\n"; }