use strict; use warnings; use Data::Dump qw/dd/; my $get = sub { my ($ref ,@path)=@_; for my $member (@path){ return undef unless exists $ref->{$member}; $ref = $ref->{$member}; } return $ref; }; my %hash = ( a=> {b=> {c=> 666} }); dd \%hash; dd $hash{a}->$get(qw/b c/); dd $hash{a}->$get(qw/x x x/); # no autovivification #dd $hash{a}{x}{x}{x}; # autovivification dd \%hash; #### { a => { b => { c => 666 } } } 666 undef { a => { b => { c => 666 } } } #### $name = $user[$idx] -> {'name'}; # may create a hash $name = $user[$idx] -> $safe -> {'name'}; # leaves @user alone $name = $person -> name; # chokes on undef $name = $person -> $safe -> name; # passes undef on