in reply to retrieving an URL

If you use the CGI.pm module, you will find that all of those "CGI environment variables" are made easy to access. For example:
$calling_url = $q->referer();