in reply to Traversing arbitrarily deep and baggy structures

++ on the idea of using XSLT in this case.

You said yourself that this was an “arbitrary and baggy structure.”   You said that you are looking for a match “anywhere in the tree.” Well, that problem has already been solved by XSLT, in the form of a search-path that begins with '//'.   For example.   So, in my humble, the “inefficiency” (for the already blisteringly-fast electronic computer) of using the generic solution, handily defeats its alternative:   Perl code that you have to write and to constantly maintain.   The time that we seek to save here is not the computer’s ... it is yours.   JM2CW.   Your Mileage May Vary.™