use strict; my %db = ( 'scores' => { 'user1' => 200, 'user2' => 190, 'user3' => 232, 'user4' => 187, 'user5' => 190 } ); my %sorted_scores; # # Generate another hash structure where # scores are used for keys and values # hold list of users who got that score. # # hash is a wonderful thing ;-) # for (keys %{$db{'scores'}}) { push @{$sorted_scores{$db{'scores'}{$_}}}, $_; } my $i = 1; for my $score (sort {$b <=> $a} keys %sorted_scores) { print "$i Place: "; for (@{$sorted_scores{$score}}) { print "$_ ($score), "; } print "\n"; $i++; } #### 1 Place: user3 (232), 2 Place: user1 (200), 3 Place: user2 (190), user5 (190), 4 Place: user4 (187),