I am unsure about what you are trying to accomplish. I of course can't run your code as an example. I just didn't understand it.
UPDATE: OMG, I got along the wrong track because of your original code which appeared to have several nested loops. The right Perl thing to "exit a single loop" is: last. You need a Label to jump a couple of levels up! But not here! Sorry about the confusion!
#!/usr/bin/perl
use warnings;
use strict;
my @x =
(
['aaaaa', 'bbbbb', 'ccccc', 'ddddd',],
['eeeee', 'fffff', 'ggggg', 'hhhhh',],
['iiiii', 'jjjjj', 'kkkkk', 'lllll',],
);
#@x is a 2D array, an AoA (Array of Array)
OUTER: for my $row_ref (@x)
{
for my $element (@$row_ref)
{
# call exit(1) to competely stop!
# with error code 1
if ($element eq 'ggggg')
{
print "stop seen\n";
next OUTER; #last; would work here
}
else
{
print "$element\n";
}
}
}
__END__
Prints:
aaaaa
bbbbb
ccccc
ddddd
eeeee
fffff
stop seen
iiiii
jjjjj
kkkkk
lllll
See also Perl "redo"....