qq interpolates no matter what opening and closing characters you use, so characters such as $ and \ will have special meaning in the string. If you don't want anything interpolated into the string, use a heredoc with single quotes:

print <<'END_HTML'; <!DOCTYPE html> <html> ... </html> END_HTML

However, generating HTML like this is pretty error-prone, as you've discovered. I suggest you look into a templating system such as Template::Toolkit.

As for debugging CGI scripts, you should check your server's logs for the cause of a 500 error. See also CGI Help Guide, Troubleshooting Perl CGI scripts, and your browser's debugging tools to inspect the HTML.

Update: The reason you're seeing a difference between qq|| and qq{}/qq() is that the latter supports nested brackets, so e.g. print qq{a{b}c}; prints a{b}c, whereas qq|a|b| is not valid (hence the 500 error), as the second | terminates the string - you'd have to write qq|a\|b| to get the string "a|b".


In reply to Re: How to print an HTML input tag with its regex pattern in Perl CGI? by haukex
in thread How to print an HTML input tag with its regex pattern in Perl CGI? by underTheRadar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.