$ cat autovivify.pl #!/usr/bin/perl use strict; use warnings; use Data::Dump qw(dump); my %h = (A=>0); print "Foo" if defined $h{Apple}{Banana}{Seahorse}; $h{Apple}{Banana}{Seahorse}=undef; print "Bar" if defined $h{Apple}{Banana}{Seahorse}; print dump(\%h); $ perl autovivify.pl { A => 0, Apple => { Banana => { Seahorse => undef } } }