my @all; construct($_, \@all) for @threads; print "$_->{'id'} $_->{'title'}\n" for @all; sub construct { my ($p, $all) = @_; push @$all, $p; construct($_, $all) for @{$p->{'children'}}; }