$ cat foo.pl use strict; use warnings; my %hash = ( foo => undef, bar => { a=>7 }, baz => 'quandary', ); for my $k ('joe', 'foo', 'bar', 'baz') { if (! exists $hash{$k}) { print "Key $k does not exist in hash\n"; next; } if (! defined $hash{$k}) { print "Key $k exists, but value is not defined\n"; next; } my $r = ref($hash{$k}); $r = "SCALAR" if $r eq ''; print "Key $k exists, refers to ", $r, "\n"; print "looking up \$hash{$k}{a}: $hash{$k}{a}\n"; } Roboticus@Waubli ~ $ perl foo.pl Key joe does not exist in hash Key foo exists, but value is not defined Key bar exists, refers to HASH looking up $hash{bar}{a}: 7 Key baz exists, refers to SCALAR Can't use string ("quandary") as a HASH ref while "strict refs" in use at foo.pl line 22.