in reply to subroutine recursion question

I don't really understand what you're doing respectively what your logic is concerning @big. My usual approach to having a recursive subroutine return a list is to either pass around a reference to the result set or to collect the results of the branches:

# Make walk() return a list and collect the results: sub walk { my ($i) = @_; my @local_results = $i; for (@{$hash{$i}}) { push @local_results, walk($_); }; return @local_results; }; ... foreach my $r (@array) { my @big = walk($r); ... };

The alternative is easier if your tree walking somehow has to check for duplicate elements, so it's more an optimization:

# Make walk() augment the result list: sub walk { my ($i,$results) = @_; # If we're called with just one argument, we need to return a fres +h list $results ||= []; push @$results, $i; for (@{$hash{$i}}) { walk($_,$results); # here, we don't care about the results of +walk() }; return @$results; }; ... foreach my $r (@array) { my @big = walk($r); ... };