You could solve it by adding two CR's at the end of each line, but it makes you dependent on details of how perl was compiled, not a good idea. Nor is it a good idea to have important characters that tend to become invisible on many editors in many modes.
So best is to either use the an escape for a double-quotish here document, or use a little bit of code to add a CR just before each line end, as already indicated in the previous answers.
The right escape to use will be either \r or \cM, depending on wether you mean logical cariage return or a control-M (these are not necessarily always the same if you want to be portable)
It's also interesting to note that a #!/usr/bin/perl line better not end on CR, since on unix that line is first read by the kernel and it will look for a program perl^M in /usr/bin, which probably doesn't exist. #!/usr/bin/perl -w will work fine though, since now the ^M is in the options and will get ignored.
update The original question was updated with WHY?
Skipping all history, it's nowadays a binmode open because it wants no strange transforms when loading bytecode. And the CR strip is so that files that have a CR after each line will work. You get such files because e.g. you created a normal text file on microsoft systems, or you transferred such a file (in binary) to a UNIX system, or you fetched something over some CRLF internet protocol without removing the CR's.
In reply to Re: Can't create DOS line endings under Unix in heredocs
by thospel
in thread Can't create DOS line endings under Unix in heredocs
by grinder
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |