Thanks graff. Appreciate the help. However, (and I should have explained this in my earlier post itself) I am deliberately trying to parse one XML line after another rather than the whole xml file at once. The reason was to find if there are any mismatched tags and then replace the tags and do other corrections. I am still stumped at the ability of XML parser to detect badly-formed XML in spite of the fact that I am not parsing the whole file at once. My assumption is that since I am parsing line by line, XML::Parser has no knowledge of the what is coming next and therefore, it should not be able to detect a badly formed XML. The fact that it does is indeed fantastic albeit completely confounding.