>perl -wMstrict -le
"my @text = qw/A B C D E F G H I J/;
;;
I:
for my $i (0 .. $#text) {
next I unless $text[$i] eq 'F';
print qq{$text[$i] is at index $i};
last I;
}
"
F is at index 5
####
>perl -wMstrict -le
"my @text = ('A' .. 'J');
;;
I:
while (my ($i, $element) = each @text) {
next I unless $element eq 'F';
print qq{$element is at index $i};
last I;
}
"
F is at index 5
####
>perl -wMstrict -le
"my @text = qw/A B C D E F G H F I J/;
;;
my @F_in_it = grep { $text[$_] eq 'F' } 0 .. $#text;
;;
print qq{these indices have an 'F': @F_in_it};
"
these indices have an 'F': 5 8