my @k = sort keys %the_hash; my $pct = 10; # what percent to keep #- WRONG -# for ( int(@k/$pct)-1..$#k ) { delete $the_hash{$k[$_]} } for ( int( @k * ($pct/100).. ) )-1..$#k ) { delete $the_hash{$k[$_]} } # Now %the_hash only contains the top 10%