use strict; use warnings; my (%hash); while (<>) { chomp; my ($text,$line) = $_ =~ m/(.+)(\d+)$/; $hash{$line} = $text; } print $hash{$_} . "\n" for (sort keys %hash)