The here document is parsed by the shell, not Perl. It's interesting; I haven't seen this before, and I'm surprised that it works this way. For example, if I put my code from 353223 into /tmp/t13 and run strace -e execve -f perl /tmp/t13 I get:
...
[pid 5261] execve("/bin/sh", ["sh", "-c", "/bin/cat << EOF\n24 is the
+ value "...], [/* 37 vars */]) = 0
...