<!--#exec cgi="/cgi-bin/scriptname.cgi" -->
The green bits are the comment placeholders which are ignored by the browser (actually pretty much anything in angle braces is ignored by the browser) but the <#!--, and --> constructs are there for human readability as comments and for syntax checkers to change the colour of comments so thery're even more human readable.
The red bit, now that's the server side include (SSI), but your webserver has to be configured to run these. As for placement I think you can place these wherever you want the script to fire.
For more direction, advise on what webserver you're using, or go to the forum for that webserver, and see if anyone can point you in the right direction of good documentation on the subject.
HTH
Paul
It's important in life to always strike a happy medium, so if you see someone with a crystal ball, and a smile on their face ...