in reply to file handling error

With all due respect to the monks who suggest that you use an XML parsing module here (I do agree with them in general), I'm afraid that approach won't work for the sample data you posted. I hope (for your sake) that you just made some copy/paste errors when you were trying to post.

When I tried using XML::Parser on it, I got failures on the entity references λ and — -- maybe a good DTD will solve this. (I just converted them to unicode numeric entities -- λ — respectively.)

But beyond that, your 15 lines of XML data is badly messed up in terms of tag layout, and cannot be parsed as XML. Here's a little one-liner that will reduce your data sample to just the tags, putting one tag per line:

perl -pe 's{(?<=>)[^<]*}{\n}g' your_file.xml
That just replaces 0 or more characters between a > and a following < with a line-feed. Look carefully at the output, and you'll see what a mess it is. One big issue is that it starts with <sec>, and there's additional XML content after the corresponding </sec> token.

UPDATE: To see what I'm talking about more clearly, pipe the output of that one-liner through grep, like this:

perl -pe 's{(?<=>)[^<]*}{\n}g' your_file.xml | grep sec