last 
last LABEL
lastThe last operator immediately exits the loop in question, just like the
break statement in C or Java (as used
in loops). If LABEL is omitted, the operator
refers to the innermost enclosing loop. The continue block, if any, is not
executed.
LINE: while (<MAILMSG>) {
last LINE if /^$/; # exit when done with header
# rest of loop here
}last cannot be used to exit a
block that returns a value, such as eval
{}, sub {}, or do {}, and it should not be used to exit a
grep or map operation. With warnings enabled, Perl
warns if you last out of a loop
that’s not in your current lexical scope, such as a loop in a calling
subroutine.
A block by itself is semantically identical to a loop that
executes once. Thus, last can be used
to effect an early exit out of such a block. See also Chapter 4 for illustrations of how last, next,
redo, and continue work.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access