in reply to local and global variable?

You declare it outside of the loop's enclosing block, and then instead of assigning to it within the block, you push onto it (so as not to clobber its contents on each iteration).

my @species = split '//', $list; my @tree; foreach my $species ( @species ) { push @tree, edit( $species ); } print "$_\n" for @tree;

...for example (and assuming that's what you're after).

It's wise to scope your variables as narrowly as conveniently possible. But if you need it at a broader scope, either declare it at that broader scope, or change your design so that it's not needed. Either solution may be fine depending on your goal.


Dave