use strict; use warnings; my %hoh; $hoh{FILENAME1} = { A => {weight => 3000, intensity => 2}, B => {weight => 4000, intensity => 3}, }; $hoh{FILENAME2} = { C => {weight => 5000, intensity => 3}, D => {weight => 2000, intensity => 7}, }; $hoh{FILENAME3} = { A => {weight => 6000, intensity => 3}, C => {weight => 1000, intensity => 4}, }; print map { sprintf qq{weight %d intensity %d Filename %s\n}, $hoh{$_->[0]}->{$_->[1]}->{weight}, $hoh{$_->[0]}->{$_->[1]}->{intensity}, $_->[0]; } sort { $hoh{$a->[0]}->{$a->[1]}->{weight} <=> $hoh{$b->[0]}->{$b->[1]}->{weight} } map { my $item = $_; my @keyPairs; push @keyPairs, [$item, $_] for keys %{$hoh{$_}}; @keyPairs; } keys %hoh; #### weight 1000 intensity 4 Filename FILENAME3 weight 2000 intensity 7 Filename FILENAME2 weight 3000 intensity 2 Filename FILENAME1 weight 4000 intensity 3 Filename FILENAME1 weight 5000 intensity 3 Filename FILENAME2 weight 6000 intensity 3 Filename FILENAME3