use strict; use warnings; use Hash::Util 'lock_keys'; my $key = 'foo'; lock_keys my %hash, ($key, 'bar'); $hash{$key}++; $hash{'key'}++; __END__