It looks like you are looking for the relaabs function in the :: Spec file . For example:
use File::Spec;
my $location = File::Spec->rel2abs($0);
print "$location\n";
This will solve $ 0 in the way you describe:
$ ./myfile.pl
/Users/myname/myfile.pl
$ ~/myfile.pl
/Users/myname/myfile.pl
Cwd:: abs_path .