Thanks all,
at least I now know what to look for. FYI it is Fedora 8, default install
sudo -u apache dig http://www.yahoo.com works
Interestingly, when I do:
sudo -u apache ./lwptest.cgi
it works, so I don't think it's related to the user permissions, pushing me back to the idea of paths.
the -u option of sudo causes it to run as the specified user, in this case 'apache'. If the apache account is set to nologin, it is the only way to run as the apache user.