sub somefunc { my($self, $context) = @_; return 1 # assumed just OK, but no further processing unless $self->{config}{key1} && $self->{config}{key1}{context} && $self->{config}{key1}{context}{$context} && $self->{config}{key1}{context}{$context}{form}; my $form = $self->{config}{key1}{context}{$context}{form}; # I can work with $form ... } #### sub is_hash { my($hash, @keys) = @_; return unless defined $hash && ref($hash) eq 'HASH'; return $hash unless @keys; my $yes; for (@keys) { $yes = undef, last unless ref $hash eq 'HASH' && %{ $hash }; $yes = undef, last unless exists $hash->{$_} && defined $hash->{$_}; $yes = 1; $hash = $hash->{$_}; } return $yes ? $hash : $yes; } #### return 1 unless my $form = is_hash($self->{config}, 'key1', 'context', $context, 'form'); #### $somedata, $key1, $key2, $idx3, $key4 ....; #### my $wanted = 'CODE'; # if key3 has a value but not a CODE ref, it croaks my $code = thefunc($somedata, $wanted, 'key1', 'key2', 'key3'); $code->(@someargs);