So I am currently trying to write a perl script that reads to a file and writes to another. Currently, the problem that I have been having is removing new line characters from p
Your lines end with CR LF. You remove the LF, leaving the CR behind. Your terminal is homing the cursor on CR causing the next line output to overwrite the last line output.
$ perl -e'
print "XXXXXX\r";
print "xxx\n";
'
xxxXXX
Fix your input file
dos2unix file
or remove the CR along with the LF.
s/\s+\z// # Instead of chomp