use Data::Dumper; my $part = { 'c' => {}, 'func' => [] }; my $main = { 'a' => { 'b' => { 'c' => {}, ### equals to $part hash reference 'func' => [] }, 'func' => [ 'd', 'e' ] } }; walk ($main); sub walk(){ my ($item, $path) = @_; if (ref $item eq 'ARRAY') { foreach (@$item) { walk($_, $path); } ### Need to change the condition/logic here... if ($item eq $main) { print "\nExpected data match here ... ", Dumper $part; } } elsif (ref $item eq 'HASH') { foreach (sort keys %$item) { push @$path, $_; walk($item->{$_}, $path); pop @$path; } } }