my $cursor = \%foo; for(qw(foo bar)) { undef $cursor, last unless exists $cursor->{$_}; $cursor = $cursor->{$_}; } print "exists\n" if $cursor;