in reply to output to a single line

Everybody has his own pet for this, but I'll go for this solution:
print file "'$var1'=='$var2'\n";
So that you know where your extra \n character is. I guess that if you see the expression on two lines, it should be in $var1, but you should try and see where the expression is broken.

In any case, you'd better be aware that when you read a text file, you also read its embedded \n's, so you'd better chomp the lines before processing them.