use strict; use warnings; my %hash; while (defined (my $line = )) { chomp $line; my ($key, $value) = split '', $line, 2; next if ! defined $value; $hash{$key} = $value if ! exists $hash{$key} || $hash{$key} < $value; } print "$_: $hash{$_}\n" for sort keys %hash; __DATA__ a 1 b 3 a 6 c 4 a 2 #### a: 6 b: 3 c: 4