The construction you are using is called a heredoc. Perl treats everything after the <<HTML expression as input until it finds a matching HTML line. "HTML; # blah blah" was NOT a match with "HTML" and was therefore not treated as the terminator. I think it's pretty picky -- even an "invisible" space after the "HTML" could fail the match and I doubt comment "#" will "work" (i.e. be stripped
rejected as you thought by the matching) and semicolon is also probably going to fail the match too.