Simply last
would work here:
for my $entry (@array){
if ($string eq "text"){
last;
}
}
If you have nested loops, then last
will exit from the innermost loop. Use labels in this case:
LBL_SCORE: {
for my $entry1 (@array1) {
for my $entry2 (@array2) {
if ($entry1 eq $entry2) { # Or any condition
last LBL_SCORE;
}
}
}
}
Given a last
statement will make the compiler to come out from both the loops. The same can be done in any number of loops, and labels can be fixed anywhere.