my $p = \$href; $p = \($$p->{$_}) for @keys; $$p = $val; #### my $p = $href; for (@keys) { return 0 if !exists($p->{$_}); $p = $p->{$_}; } return 1;