in reply to Re: Better solution to the code
in thread Better solution to the code

The idea with the hash won't work, because the regex match searches for a matching substring, the hash lookup compares the whole string.

But that reminds me of another possible optimization: if @tag doesn't contain regexes but only constant substrings, index might speed up things.

So instead of if ($_ =~ m/$something/){ ... }, you can write if (0 <= index $_, $something).