http://qs1969.pair.com?node_id=1143109


in reply to \R not working as (I'd have) expected on Windows Strawberry perl

On MSWin, all filehandles are opened with the :crlf layer by default. Therefore, the $_ coming from <> doesn't contain the \x0d anymore. To get the Unix behaviour, do
binmode FH, ':raw';

Update: I wasn't able to make this work with -n and filename argument - somehow, you have to change the bimode of an open filehandle, but -n opens it and reads from it at the same time or something (anyone?). Therefore, I had to write the loop myself:

perl -wE 'use open IN => ":raw"; while (<>) { /(\R)/; say (unpack "H*" +, $1); }' file

Update 2: -M works, thanks Anonymous Monk:

perl -Mopen=IN,:raw -wnE '/(\R)/; say unpack "H*", $1' file
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ