More backtracking examples
Backtracking might be costly so one should try to avoid useless backtracking. Perl regx have special form of parentheses: (?>…). These are called Perl’s “don’t-ever-backtrack-into-me” markers. They will tell the regex engine that the enclosed sub-pattern can safely be skipped over during backtracking. As we know that the re-matching the contents either won’t succeed or, if it does succeed, won’t help the overall match. So these markers helps to avoid useless backtracking and saves a lot of time.
Some more useful links and examples can be found at:
http://codenode.com/2010/02/28/debugging-perl-regex-backtracking/
Perl Regx documentation page Perlre on Perldoc
Perl Best Practices by Damian Conway