I asked something similar, related to modules - see node Get path to module
As previous responders stated, the use of modules in such a case will make your life easier here - and it's not a big jump to turn your script into a module.
Comment on Re: Getting perl file path from Function