use strict; use warnings; use Benchmark qw(cmpthese); our $global_hash = { 'a' => 'A', 'b' => 'B'}; my $lexical_hash = { 'a' => 'A', 'b' => 'B'}; use constant CONST_HASH => { 'a' => 'A', 'b' => 'B'}; cmpthese(-2, { 'hash' => sub { for my $x (qw(a b a b a b)) { my $y = { 'a' => 'A', 'b' => 'B'}->{$x}; }}, 'global_ref' => sub { for my $x (qw(a b a b a b)) { my $y = $global_hash->{$x}; }}, 'lexical_ref' => sub { for my $x (qw(a b a b a b)) { my $y = $lexical_hash->{$x}; }}, 'const' => sub { for my $x (qw(a b a b a b)) { my $y = CONST_HASH()->{$x}; }}, });