$foobar='D';
$sep = chr(1);
@array = ('A','B','C','D');
if (($sep.join($sep,@array).$sep) =~ m/$sep$foobar$sep/) {
print "Found a $foobar in \@array!";
}
####
$foobar='D';
%hash = ( 'A' => undef, 'B' => undef, 'C' => undef, 'D' => undef );
print "Found a $foobar in \%hash" if exists $hash{$foobar};
##
##
@array = ('A','B','C','D');
for (@array) {
$hash{$_} = undef;
}
#now we have the same hash as in the previous example.
#so, you can do this repeatedly with out a hit:
$foo = 'D';
if (exists $hash{$foo}) {
print "There was a $foo in the array\n";
}