in reply to More than one regexp.

My feeling would be to try something like:
my $patternlist = join( "\t", @patterns ); if( $patternlist =~ /\t$input(.*)\t/ ) { print $input.$1; }
NB This will do something akin to "command matching"

If you wanted to match whole patterns only, then:

my $patternlist = join( "\t", @patterns ); if( $patternlist =~ /\t$input\t/ ) { print $input; }
of course RatArsed

Replies are listed 'Best First'.
Re: Re: More than one regexp.
by eg (Friar) on Jan 19, 2001 at 15:05 UTC

    The problem with this is that you have to compile a new regular expression for every line of $input. You can do this sort of alternation in a regular expression like

    my @patterns = qw/ test good /; my $alt = join('|', @patterns); my $re = qr/(?:$alt)/; while (<DATA>) { if ( /$re/ ) { print "+ $_"; } else { print "- $_"; } } __END__ THis is a test this is only a test now is the time for all good men to come to the aid of their country.

    Other than perlop and perlre, a good place to look for regular expressions is the Jeffery Friedl book, Mastering Regular Expressions.

      Assuming that your target strings don't change, tack a /o onto the assembled regexp invocation to compile it once. (See perlre for details.)