in reply to Hopefully a simple mistake

Do you have the British Spelling Filter attached to your filehandle? :)

Why don't you send along your test data (the contents of @settings and @lines, I guess), so we can try to see what's going on.

Also, are you sure that the two print statements that are giving you the incorrect output are occurring right after one another and not at different times through the loop?

(By the way: the name of the filehandle is STDOUT, not <STDOUT>.)