It should work fine as written provided that ENDHEADER is at the very start of a line and nothing else follows it (though I can't tell for sure as you should put <code> tags around your code so we can also see your code formatting which is important in this case). As per perlop:

The terminating string must appear by itself (unquoted and with no surrounding whitespace) on the terminating line.

use diagnostics;
print <<FOOOBAR;
__END__
Can't find string terminator "FOOOBAR" anywhere before EOF at - line 2+ (#1)
(F) Perl strings can stretch over multiple lines. This message me+ans
that the closing delimiter was omitted. Because bracketed quotes +count
nesting levels, the following is missing its final parenthesis:
print q(The character '(' starts a side comment.);
If you're getting this error from a here-document, you may have in+cluded
unseen whitespace before or after your closing tag. A good program+mer's
editor will have a way to help you find these characters.
Uncaught exception from user code:
Can't find string terminator "FOOOBAR" anywhere before EOF at +- line 2.

The behaviour can't be changed because of backwards compatibility. The best that can be done is too clearly document the trap, and that has been done. Perl 6, not constrained by backwards compatibility, does allow whitespace before the token.

to be fair, if you place:
use diagnostics;
at the start of the code it will say:
"If you're getting this error from a here-document, you may have included whitespace before or after your closing tag. A good programmer's editor will have a way to help you find these errors."

Went to join the gridlock to see it
Held an eclipse party
Watched a live feed
I cn"t see tge kwubosd to amswr thus
I tried to see it, but 8000 miles of rock got in the way
What eclipse?
Wanted to see it, but they wouldn't reschedule it
Read the book instead