in reply to prevent perl script running from browser

As others said: If you don't want the script to be started from the webserver, don't place it in directories accessible via the webserver.

In case of shared hosting, you are often limited to directories accessible via the web server. A .htaccess file can help. But you can also check for the environment variable GATEWAY_INTERFACE. Unless you have really messed up your setup, it is set if and only if a program is executed as CGI (i.e. from the webserver), it is set by the webserver, and it can't be changed by HTTP requests. See https://tools.ietf.org/html/rfc3875#section-4.1.4:

if (exists $ENV{'GATEWAY_INTERFACE'}) { # invoked as CGI # print out a short message and abort my $q=CGI->new(); print $q->header(-status=>'400 Bad Request', -type=>'text/html'), $q->start_html(-title=>'Bad Request'), $q->h1('Bad Request'), $q->end_html(); exit 0; } # not invoked as CGI if you get here

And by the way: from which digital junkyard did you copy this nonsense?

$ENV{PATH} = "/usr/sbin/sendmail -t -i"; #for sendmail

$ENV{'PATH'} contains a ":"-separated list of directories to search for executables. Putting the name of an executable and parameters there is nonsense and won't do what you might expect. You want $ENV{'PATH'} set to a safe value, this is usually /bin:/usr/bin and nothing else.

Some more notes:

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)