in reply to Re: Dynamic regexp from array values
in thread Dynamic regexp from array values

jdporter makes a very good point above. I just want to make it explicit because it's a fairly common over-generalization: If you're only testing for string equality, don't use regular expressions at all. I can't tell from your note whether that's the case or not, but if so, a regular expression is much more work than necessary.

In that case, using a hash as shown above will work, and will be faster, though it may consume more memory. Another alternative is to use a simple loop:

foreach (@target_strings) { if ($data eq $_) { doSomething(); last; } }
(I'm guessing that you can short-circuit the loop if any one of the targets matches.)