Q:

Perl writes LF as CRLF on Windows

I have gotten some stray Windows-style line endings in a couple of files and I am trying to resolve it on my Windows machine with the following command:
perl -pi -e s/\R/\n/ example.txt

After running this all line endings in the files this was run on have been changed to CRLF, which is the opposite of my intention. Why is perl doing this, and is there anything I can change to make this work as I expect it to?
I am using Strawberry Perl version 5.28.

A:

Windows builds of Perl adds a :crlf layer to handles by default. This converts CRLF to LF on read, and LF to CRLF on write. (Some other languages do something similar.)
You need to tell Perl it's not a text file. Unfortunately, one can't do that with ARGV, the special handle you are using.
perl -pe"BEGIN { binmode STDOUT }" example.txt >example.new.txt
move example.new.txt example.txt

