sub buk { use List::Util qw[sum]; my( $hashref, $start, $end ) = @_; # Added sanity check. Slowed it a tad return undef unless exists $hashref->{$start} and exists $hashref->{$end}; my @keys = grep{ $_ >= $start && $_ <= $end } keys %{ $hashref }; return sum( @{ $hashref }{ @keys } ) / @keys; } __END__ P:\test>278169 0.503353665487943 0.503353665487943 Rate orig buk orig 1.28/s -- -42% buk 2.23/s 73% --