my @coderefs; for my $num (10, 20, 30) { my $ref = sub {print "$num\n"}; push @coderefs, $ref; } #Note: $num has ceased to exist here... #...yet the following subs can still see the value of #$num at the time they were created: $coderefs[0]->(); $coderefs[2]->(); --output:-- 10 30