Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
In summary, whenever two subpatterns X and Y are mutually exclusive in terms of the strings they match, then rewrite any instance of: X | Y as: (?> X | Y ) and rewrite: X* Y as: (?> X* ) Y String Comparisons Prefer fixed-string eq comparisons to fixed-pattern regex matches. If you're trying to compare a string against a fixed number of fixed keywords, the temptation is to put them all inside a single regex, as anchored alternatives: # Quit command has several variants... last COMMAND if $cmd =~ m{\A (?: q | quit | bye ) \z}xms;