use Benchmark qw {:all}; use 5.016; my %hash; # set up the hash for (1001..2000) { $hash{$_}++; } # two keys we use below our $key1 = 1001; our $key2 = 1002; # hash key 1 is SV $hash{$key1} = 1; # hash key 2 is RV $hash{$key2} = {1..10}; # assign to global as a baseline our $xx_global; # keys are short for formatting reasons # (and kept the same as in the original post) # char1: e = exists check, v = value check # chars 2,3: ck = constant key, vk = variable key # chars 4,5: sv = key contains scalar value, rv = key contains reference # char 6: l = assign to lexical, g = assign to global # thus # ecksvl means "exists check using constant key, scalar value, assigned to lexical" my %checks = ( evksvg => '$xx_global = exists $hash{$key1} ? 1 : 2', vvksvg => '$xx_global = $hash{$key1} ? 1 : 2', evkrvg => '$xx_global = exists $hash{$key2} ? 1 : 2', vvkrvg => '$xx_global = $hash{$key2} ? 1 : 2', ); cmpthese ( -2, \%checks );