use strict; use warnings; use Path::Class; my $rootdir = ... # however it happens my $relative_path = file($0)->relative($root_dir); # btw, this does the same if all you want is # the script name: use FindBin; my $name = $FindBin::Script; # there's also $FindBin::Dir, ::RealDir and ::RealScript, # the last two are only relevant for resolving soft links. # Here's Yet Another Way, using Path::Class again: my $script = file(__FILE__)->basename; # If you want to be thorough... $script = file(__FILE__)->absolute; $dir = $script->dir; $script = $script->basename;