Use
$/ = undef;
before $document = <FILE>;
. $/
is the input record separator, which is a newline by default. By redefining it to undef
, you are saying there is no field separator. This is called "slurp" mode.
Other solutions like undef $/
and local $/
(but not my $/
) redeclare $/ and thus produce the same effect.