When looking for short literals, index is more efficient than a regex:
my @matches = grep index( $lineFromSomeFile, $_ ) > -1, @terms;
Update: Added the link and the qualifier "short" in response to kaif's comment++. How short is short? When I tested random (but constant) strings and substrings of lengths 80 and 8, respectively, which are "typical" lengths for a line and a word, index was about 20% faster than the corresponding regex. I imagine that it is this sort of analysis that's responsible for the widespread reputation of index as being superior to regexes. Clearly, as kaif shows, the ratio of speeds is sensitive to the sizes of the string and the substring being searched, but I have not done a detailed analysis beyond this, and what is posted in the node linked above.
the lowliest monk
In reply to Re^2: One line assigment statement with regex match
by tlm
in thread One line assigment statement with regex match
by ketema
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |