CGI is not a language, it is a standard for passing information from an http server (Apache, IIS, etc) to an external handler (another program); hence the name "Common Gateway Interface".
Perl is a language that can be used as such an external handler, PHP is another language that can be used that way. Web servers can be configured to use either.
When used as CGI handlers, the CGI passes information to the program, then takes the output from STDOUT of the program (Perl or PHP) and sends it back to the browser.
What exactly are you trying to do?