http://qs1969.pair.com?node_id=6637


in reply to How to find out if X is an element in an array?

You could do it like this:
my $element = "catchme"; my @array = ( "catchme", "if", "you", "can" ); if ( @found = grep { $_ eq $element } @array ) { my $found = join ",", @found; print "Here's what we found: $found\n"; } else { print "Sorry, \"$element\" not found in \@array\n"; }
I know that's a little longer than other answers but, I think this gives a little more detail and is easier to see how it works.