my %weight = ( ); foreach my $filename (keys %hoh) { my $psubhash = $hoh{$filename}; foreach my $letter (keys %$psubhash) { my $weight = $psubhash->{$letter}->{'weight'}; my $intensity = $psubhash->{$letter}->{'intensity'}; $weight{$weight} = [ $intensity, $filename ]; } } my @weight = sort { $a <=> $b } keys %weight; foreach my $weight (@weight) { my $p = $weight{$weight}; my ($intensity, $filename) = @$p; printf "weight: %4d intensity: %d Filename: %s\n", $weight, $intensity, $filename; }