in reply to CGI cookies

The header method in the CGI module returns the content-type header. If no argument is supplied then the content type defaults to text/html, so

print $query->header()

would do exactly the same as your

print "Content-type:text/html\n\n";

If you include other arguments (such as -cookie => $cookie) then these are included in the return header as well.