Ok. Here's one way that stores the found status of the search and terminates the foreach loop early if/when it does find one.
#! /usr/bin/perl -w
use strict;
# What we're trying to find
my $target = shift;
# Flag to hold found status
my $found;
# List to search through
my @words = qw/bcd efg hij klm/;
# Look through the list
foreach (@words) {
# This will be true if they match
$found = $target eq $_;
# We found one, get out of this loop early
last if $found;
}
# Print if nothing was found
print "$target not found$/" unless $found;
But you just can't beat eieio's use of grep() below. Fantastic, ++ |