You seem to be more interested in playing with regexps than in really solving the problem, but may I interest you in an alternate way, a fun way in its own right, where the parsing has already been done. A way that might even work reliably?
Look for modules that work on the parsed version, in the B:: namespace, such as B::Deparse.
And of course Hook::LexWrap will probably just do what you want...
In reply to Re: parsing code, finding block boundaries
by mirod
in thread parsing code, finding block boundaries
by revdiablo
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |