Thanks graff. You have been great help. Yes, you are right about stressing on the point about OP and point is well taken. I understand your solution. But, what still confounds me completely is how the XML::Parser is able to detect the badly formed XML file even if the program is parsing one line at a time. This obviously could be because my understanding of the XML::Parser is limited.
One of the unintended consequences that your reply had gave me an insight into a problem that I had earlier, but never got around asking the permonks site. Aren't unintended consequences great when they turn out to be good? Thanks macho again!