my ($redo, $next, $last)=(0, 0, 1); { my $first = 0; for (0, 1) { if (not $_ and $first++) { $redo=1; $last = 0; last; } if ($_) { $next = 1; $last = 0; last; } main_code(); $last = 0; last; } } $,=" & "; print ($next, $redo, $last); sub main_code { redo; } # replace redo with next and/or last to test