if( defined $ENV{'GATEWAY_INTERFACE'} ) { # we are under CGI } else { # we are under command line }