for my $i (1..$numberOfBestFrags) { print "for loop nr. $i \n"; my $nrOfKeys = scalar keys %fragmentResultSetH; print "nr of keys = $nrOfKeys \n"; my $nrOfvalues = scalar values %fragmentResultSetH; print "nr of values = $nrOfvalues \n"; my $index = 0; my $maxGoodness = 0; while(($key, $value) = each %fragmentResultSetH) { if($value{goodness} > $maxGoodness) { $maxGoodness = $value{goodness}; $index = $key; }   ; } push @tenBestFrags, $fragmentResultSetH{"$index"}; delete $fragmentResultSetH{"$index"}; }