A more generalized way to extract content from an XML document is XPath expressions, and a good Perl XML::LibXML mini tutorial on it can be found at
The advantage of this approach is that it is basically akin to “querying” the XML document, which neatly avoids you having to write your own procedural (Perl) logic to try to do the same thing. The XPath essentially describes what you want, and it’s up to LibXML to find it for you. (XPath is an industry-standard technology that is by no means limited to Perl.)
2018-07-23 Athanasius linkified references to module and github.