use strict; use warnings; my @data = ( { ID => 'AA', Score => 20 }, { ID => 'D', Score => 30 }, { ID => 'F', Score => 7 }, { ID => 'AA', Score => 3 }, ); ## choroba's solution: my %by_id; push @{ $by_id{ $_->{ID} } }, $_->{Score} for @data; # Sort the scores for each id. $_ = [ sort { $b <=> $a } @$_ ] for values %by_id; # Sort the ids by the highest score. for my $id (sort { $by_id{$b}[0] <=> $by_id{$a}[0] } keys %by_id) { print "ID: $id\tScore: $_\n" for @{ $by_id{$id} }; }