{ my @todos; foreach my $elt ( ... ) { $_->() for @todos; # Correction for Roy Johnson @todos = (); ... push @todos, sub { print "$elt\n" }; } }