my @a; for my $i (1..8) { foreach ('once') { my $x; push @a, \$x if $i >= 4; print(\$x, "\n"); } pop @a if $i >= 7; }