my @k = sort keys %the_hash; my $pct = 10; # what percent to print #- WRONG -# for ( 0..int(@k/$pct)-1 ) { for ( 0.. int( @k * ($pct/100) ) )-1 ) { printf "%s => %s\n", $k[$_], $the_hash{$k[$_]} } #### 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%