in reply to source code of cgi script directly opens in browser

That isn't a Perl problem. Your web server isn't configured to do what you want it to do. It hasn't been told to treat the file as a CGI script.

If you want to treat all .cgi files in a directory and subdirectories as CGI scripts:

<Directory /some/dir/htdocs/> Options +ExecCGI AddHandler cgi-script .cgi </Directory>

If you want to treat all files in a directory and subdirectories as CGI scripts:

<Directory /some/dir/cgi-bin/> Options +ExecCGI SetHandler cgi-script </Directory>

There's also ScriptAlias.