Perl Programming/Keywords/binmode

The binmode keyword
The binmode function sets that FILEHANDLE is read or written in "binary" or "text" mode on systems where the run-time libraries distinguish such file types. If FILEHANDLE is an expression, its value is taken as FILEHANDLE name. The function returns true on success and undef otherwise, setting $! (errno). It is good programming practice to use it where appropriate and never to use it otherwise, as a missing call will result in errors on operating systems like DOS or Windows that differentiate such file types.

If LAYER is present, it is a single string that may contain multiple directives, which alter the behaviour of the <tt>FILEHANDLE</tt>. With <tt>LAYER</tt>, using binmode on a text file makes sense. Without <tt>LAYER</tt> or specified as <tt>:raw</tt>, the filehandle is made suitable for passing binary data. This includes turning off possible <tt>CRLF</tt> translation and as opposed to Unicode characters, marking it as bytes.