http://www.perlmonks.org?node_id=833943


in reply to a sub within a sub -- revisiting

bar is still visible outside of foo, so make it lexical
sub foo { my $bar = sub { my ($i) = @_; push @arrb, $arra[$i]; }; $bar->($#arra); ... }