in reply to next and last within subs

The following three lines are equivalent to your subroutine. Use them each place they are needed.
last if $x > $stop; next if $y eq $text; foobar();
Bill