for my $i (1..$numberOfBestFrags) { my $index = 0; my $maxGoodness = 0; for our $firstHashKey (keys %fragmentResultSetH) { for our $secondHashKey (keys %{ $fragmentResultSetH{$firstHashKey} } ) { if($secondHashKey =~ m/goodness/) { my $tmp = $fragmentResultSetH{$firstHashKey}{$secondHashKey}; if($tmp > $maxGoodness) { $maxGoodness = $tmp; $index = $firstHashKey; } } } } push @tenBestFrags, $fragmentResultSetH{"$index"}; delete $fragmentResultSetH{"$index"}; }