in reply to XPath searching too slow

XML::LibXML can search for XPaths, and since it's mostly a wrapper (a very good one, that is) around a C library it could be quite fast. But of course you'd have to benchmark that first.

If you need to make many queries, you can also build relational indexes for xpath, but that's likely to require quite a lot of work.

Or maybe you could just use a different templating technique.