Labels


Normally the last and next keywords are related to the innermost loop. In some cases that's not good. Perl allows us to define labels in front of loops and then to use those labels in conjunction with last or next to go to the last or next iteration of the specified loop.


examples/perlarrays/labels.pl
use strict;
use warnings;


OUTER:
while (1) {
    print "start outer\n";
    while (1) {
        print "start inner\n";
        last OUTER;
        print "end inner\n";
    }
    print "end outer\n";
}
print "done\n";