in reply to sorting arrays

If this data fits easily in memory, go over each row and extract the id from it, then insert ($id => $original_line) into a hash, if this id is new. Then print the hash, sorted by keys.

my %seen; for my $row (@data) { my ($id) =~ /^(\d+):/ or die "bad line: [$row]"; $seen{$id} ||= $row; } print $seen{$_}, "\n" for sort {$a<=>$b} keys %seen;