#!perl use 5.012; # strict, // use warnings; use JSON; # create the JSON object from a string (you could get it from a file, or whatever) my $json = JSON->new->allow_nonref(); my $string = <decode($string); #recurse through the top level my @retvals = h_recurse($href); use Data::Dumper; print Dumper @retvals; exit; # define two subroutines, for recursing a hashref or an arrayref sub h_recurse { my $r = shift; my @ret = (); die "'$r' not a hashref" unless UNIVERSAL::isa($r,'HASH'); # go through each pair while(my ($key,$val) = each %$r ) { # if it's a hash or array ref, recurse into it; add the returns from the recursion to your active return list push @ret, h_recurse($val) if UNIVERSAL::isa($val,'HASH'); push @ret, a_recurse($val) if UNIVERSAL::isa($val,'ARRAY'); # if a literal key/value pair matches your requirements, add it to your return list push @ret, $r if $key eq 'componentId'; # change the logic here if you want only componentId whose value matches something specific } # once done, return @ret; } sub a_recurse { my $r = shift; my @ret = (); die "'$r' not an arrayref" unless UNIVERSAL::isa($r,'ARRAY'); for my $val (@$r) { push @ret, h_recurse($val) if UNIVERSAL::isa($val,'HASH'); push @ret, a_recurse($val) if UNIVERSAL::isa($val,'ARRAY'); } return @ret; }