I'm gonna guess that if the same code works on the command line but not when run as a CGI, the environment is different when run as a CGI. This is fairly common, as the CGI environment is more prone to Naughty People trying to break things so is set up to be paranoid.
Here's a little perl script you can run as a CGI to spit out a copy of the environment, for comparison with what you get at the command prompt.
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<HTML><BODY>";
print "<TABLE><TR><TH>Environment variable</TH><TH>Value</TH></TR>";
foreach (sort keys %ENV)
{ print "<TR><TH ALIGN=RIGHT>$_:</TH><TD>$ENV{$_}</TD></TR>"; }
print "</TABLE>";
print "</BODY></HTML>";
You also need to be aware that the web server would normally run as a seperate user, so may have different permissions to what you do. To investigate whether you have the right permissions on the various files you need access to, see perldoc -f -r. |