use strict; use Benchmark qw(:all); timethese(1000,{ "Foreach" => sub{ my %hash = map{$_=>1} (1..10000);}, "Map" => sub{ my %hash; $hash{$_} = 1 foreach (1..10000);} })