Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Matching a long list of phrases

by Sartak (Hermit)
on Aug 14, 2006 at 16:55 UTC ( [id://567281] : note . print w/replies, xml ) Need Help??


in reply to Matching a long list of phrases

As the Camel says, you should use /Gandalf/ || /Saruman/ || /Radagast/ over /Gandalf|Saruman|Radagast/ for efficiency.
my @phrases = map { qr/$_/ } # precompile regexes, may not be what you + want though ( 'phrase one', 'phrase two', 'a different phrase', 'yet another match', 'one more to match', 'single', 'word', 'matches', ); PHRASE: foreach my $phrase (@phrases) { last PHRASE if $incoming{'text'} =~ /($phrase)/; } if (defined $1) { # Matched phrase in $1. } else { # No match. }