if (exists $locs{$loc}) { # do something... } else { die "key $loc does not exist"; }