While Perl's regular expressions are generally hard to access and modify on the level you require, the Parse::RecDescent module can probably do the job you require pretty well. You can produce a parse tree with P::RD and then evaluate it, skipping the nodes you need to avoid. You can also have actions associated with "good" nodes that execute them, and actions associated with "bad" nodes that print a warning, die, whatever is appropriate.
In P::RD nodes are called "rules" and you should be able to pick up basic usage of the module in just a few minutes.
It is possible to actually modify rules while the parser is running, but chances are you'll be happy with a parse tree.