while () { chomp; #or s/\s*$//; print OUT "$_\n"; #this "resets" line ending to your OS's version }