#! perl use strict; use warnings; use Test::Deep::NoTest; my $x = { c => {}, func => [], }; my $x1 = { func => [], c => {}, }; my $x2 = { func => [], c => { s => 't' }, }; my $main = { a => { b => { c => {}, ### equals to $part hash reference func => [], }, func => [ 'd', 'e', ], }, }; printf "%s found\n", walk($main, $x ) ? 'Match' : 'No match'; printf "%s found\n", walk($x, $x1) ? 'Match' : 'No match'; printf "%s found\n", walk($main, $x2) ? 'Match' : 'No match'; sub walk { my ($whole, $part) = @_; my $ref = ref $whole; return 1 if eq_deeply($whole, $part); if ($ref eq 'ARRAY') { for (@$whole) { if (eq_deeply($_, $part)) { return 1; } else { return 1 if walk($_, $part); } } } elsif ($ref eq 'HASH') { for (keys %$whole) { if (eq_deeply($whole->{$_}, $part)) { return 1; } else { return 1 if walk($whole->{$_}, $part); } } } return 0; }