use Benchmark qw[ cmpthese ]; $h{ $_ } = 0 for 1 .. 100; cmpthese( -3, { for => q[ $h{ $_ }++ for keys %h; ], while => q[ $h{ $_ }++ while $_ = each %h; ] }); Rate while for while 11937/s -- -23% for 15544/s 30% -- $h{ $_ } = 0 for 1 .. 1000; cmpthese( -3, { for => q[ $h{ $_ }++ for keys %h; ], while => q[ $h{ $_ }++ while $_ = each %h; ] }); Rate while for while 1165/s -- -26% for 1581/s 36% -- $h{ $_ } = 0 for 1 .. 10000; cmpthese( -3, { for => q[ $h{ $_ }++ for keys %h; ], while => q[ $h{ $_ }++ while $_ = each %h; ] } ); Rate for while for 80.0/s -- -8% while 86.9/s 9% -- $h{ $_ } = 0 for 1 .. 5000; cmpthese( -3, { for => q[ $h{ $_ }++ for keys %h; ], while => q[ $h{ $_ }++ while $_ = each %h; ] }); Rate while for while 207/s -- -15% for 243/s 17% -- $h{ $_ } = 0 for 1 .. 8000; cmpthese( -3, { for => q[ $h{ $_ }++ for keys %h; ], while => q[ $h{ $_ }++ while $_ = each %h; ] }); Rate for while for 119/s -- -0% while 119/s 0% --