in reply to Regexp Speed Concerns
As far as your test results go, to paraphrase the Third Camel, short-circuit alternation can be faster than the corresponding regex when the optimizer determines that your search expression (or portions of your search expression) can simply be handed off to a Boyer-Moore search algorithm which does very fast string matching. Note the word "string". This is why the following:
/at/ || /bt/ || /ct/
is faster than
/at|bt|ct/
Just as in your pattern 0, the regex engine does not even have to become involoved - there is no backtracking involved, no backreferences, and no quantifiers, hence simple string searching can be done with the B-M algorithm, which, as stated, is very fast. In fact, the longer the pattern, the faster B-M is, on average, because it attempts to be somewhat intelligent and selectively skips sections of input where it determines that no match is possible, rather than trying and backtracking over every single character. This is relevant to the large expressions you mentioned - if they involve long constant strings, then you will likely see a significant speed-up by using short-circuit alternation as demonstrated in your pattern 0.
Of course, for increasingly complex patterns with multiple quantifiers, etc., you are better off with a carefully crafted regex.
Other optimizations:
-use //o or qr// to avoid recompilation if the pattern does not change
-As TChrist et all teach us, have your program build a string containing the expression and eval "$code" it
-create a nonbacktracking subpattern using (?>PATTERN). This is like the cluster without capture modifier you used in patterns 3 and 4 (?:PATTERN) except it suppresses backtracking on any quanitifiers or alternations inside the subpattern.
For more about the Boyer-Moore algorithm, see:
A Fast String Searching Algorithm, R.S. Boyer & J.S. Moore in Communcations of the Association for Computing Machinery, 20(10), 1977, pp762-772
The classic CS text on regular expression theory (see Ch. 3):
Compilers - Principles, Techniques, and Tools, by Aho, Sethi, and Ullman
A regular expression is pretty smart, but it's smart like a horse. It can get distracted if it sees to much at once. So sometimes you have to put blinders onto it.
-Programming Perl, 3rd Ed.