http://www.perlmonks.org?node_id=246772


in reply to Incorporating On-The-Fly Graphics In CGI output

You can't incorporate binary graphic data directly into a HTML web page, which is what your CGI object is producing. You'll need to incorporate an <img> tag which then requests the picture data.

One way would be to write the image to a temporary file, then use this filename for your image tag.
Another way would be to separate out the graph-plot into a separate script or a re-entry into the existing script, then call it from your image tag... <img src='graph.cgi?drawpic=1'> or something, printing the binary data directly with the correct MIME-type header.

Hope this helps.