in reply to Hopefully a simple mistake
Some questions:
1) What is your playform/OS, and Perl version?
2) Setting any switches in the first line of the script?
3) Setting any Perl global vars before the first foreach?
4) Can we see some of what's in @settings and @lines?
Also (I am shooting in the dark here, don't laugh) what
happens when you re-assign $lineout to "$temp1 = $temp2\n"
between your print statements?