I've just implemented an experimental regex extension, which allows you
to do things like match balanced parentheses, without having to embed any
code in your regex. The implementation isn't
in perl (yet?), but
this is still a firm Perl topic, and it raises questions about what
features Perl's regexes ought to have.
I wrote a web page
about it, but here's the rough idea. You can treat each parenthesised group
in your regex as if it were a little subroutine, and make calls to it from
within your regex. The power comes from the fact that you can make recursive
calls, so you can write
to match strings which have balanced parentheses, for example.
My favourite so far is a regex to detect palindromic sentences, ignoring
spacing and punctuation.
If you want to try it out, follow the instructions
Let me know what you think.