in reply to XML::LibXML::Reader giving wrong matched element

XML::LibXML::Reader is a pull parser. It lets you do something on the closing tag, too. If you are not interested in closing tags, just add
unless $reader->nodeType == XML_READER_TYPE_END_ELEMENT;
after the push.