in reply to XML::TokeParser and malformed XML

Another possiblity might be:

while ($token = $p->get_token()) { if ($token->is_tag()) { # do something } }

Note: I have no experience with XML::TokeParser so it is possibile that this code is completly useless...