grep { $_->text eq $search_text } map { $_->children } @data; # or grep $_->text eq $search_text, map $_->children, @data;