Если я понимаю ваш вопрос, вы можете использовать realpath
из Cwd .
$ cat ./mycode
#!/usr/bin/env perl
use strict;
use warnings;
use Cwd;
print "called as '$0'\n";
print "lives in '", Cwd::realpath($0), "'\n";
$ ./mycode
called as './mycode'
lives in '/Users/jrf/Sandbox/mycode'