$0 is a special variable that holds the full path of the script, if you launched it with the full path . If you launch it with ./ for example you will not have the full path. Strip the file name from the path with File::Basename .
use cwd will give you the cwd function that returns the current path .