There is no magic \n
. Both \n
and \r
always mean exactly one character, and on all ASCII-based platforms that is \cJ
and \cM
respectively. (The exceptions are EBCDIC platforms (for obvious reasons) and MacOS Classic (where \n
and \r
both mean \cM
).)
The magic that happens on Windows is that when doing I/O through a file handle that is marked as being in text mode, \r\n
is translated to \n
upon reading and vice versa upon writing. (Also, \cZ
is taken to mean end-of-file – surprise!) This is done at the C runtime library layer.
You need to binmode
your socket to fix that.
You should also remove the /s
and /m
modifiers from your pattern: since you do not use the meta-characters whose behaviour they modify (.
and the ^
/$
pair, respectively), they do nothing – cargo cult.