On Sat, Apr 9, 2011 at 3:29 PM, <sono...@fannullone.us> wrote: > Hi Chris, > >> It is detecting but not testing if any particular 2 words are in a >> text field and I think that's what you explained you were testing for. > > Sorry if my first post was misleading. Those were just some examples. > I'm looking only for an occurrence of _any_ two words in that list, not a > particular combination. Though the most common combo is a PO Box and a > street address. > >> You can say: if (/box/i && /street/i) { >> rather than the more complex: if ($str =~ /box/i && $str =~ /street/i) > >> my $address_count = () = $str =~ /box|street|avenue|lane|apo/ig;
what does print $var = () = $str =~ /regex/; do? particularly the '= () ='? per the question, maybe something like this: my @match = [ qr/one/i, qr/two/i, qr/etc/i ]; my @words = split /[^\s]+/, $fields; my $count = 0; foreach my $word (@words) { $count++ if( $word ~~ @match ); } print "cool\n" if $count >= 2; there might be a better way to do this. i generally use this if i want to test for any regex in a line as it just matches the first thing and moves on... it's possible you can look into how to alter this to match two. if there is a way to do this, let me know. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/