That's another quirk of using the PHP front end. You don't use Perl in the globals. For examples on how to do equivalents in PHP, see the time and date globals.
It would be something like:
return isset($HTTP_SERVER_VARS["HTTP_REFERER"]) ? $HTTP_SERVER_VARS["HTTP_REFERER"] : "nowhere";
Remember, when you use the tag in the template, you access it by:
Note the ()'s, as now it's a function, not a regular variable.