in reply to regexp match arg1 AND arg2

If you particularly want a single regular expression, you can get it by using lookahead:

my $re = join ' ', map "(?= .*? \Q$_\E)", @ARGV; if ($entry =~ /^ $re/sx) { ... }

That would turn your example arguments into something like:

m{ ^ (?= .*? bill ) (?= .*? clinton ) }xs
so it matches if:
from the start fail unless we can find some characters followed by "bill" _and_ (still from the start) fail unless we can find some characters followed by "clinton" succeed

I'm not sure how efficient that is, but it should be ok; if speed is important it would be worth benchmarking against some alternatives. Don't forget that when looking for an exact string match, index() can be faster than m/\Q$str\E/, and that if you're going to match one string against many regexps study($string) can help.

Hugo

Replies are listed 'Best First'.
Re: Re: regexp match arg1 AND arg2
by Jaap (Curate) on Feb 18, 2003 at 11:27 UTC
    Wow this is exactly what i meant. Thank you! It works like a charm.