That's very neat! If you have any tests/examples, would you be willing to put them here? I'd like to put the above in a PDL tutorial section, together with the PDL equivalents. It won't surprise you that those would probably be very concise, but I don't want to spend 5 minutes producing a somewhat unreliable and partly-incorrect version, when with tests that show inputs and outputs I could spend 6 minutes making a sufficiently-correct version :-)
That would even help those who don't know PDL but might be a little interested in some simple idioms!