Hashing of tools by shells has not been mentioned. It may not be part of the problem but on invocation many, if not all, shells examine the $PATH variable and make a table of executables that it finds. The table is then converted to a hashed lookup array in order to improve speed of response. (That probably makes little sense today but it was started during the days of mag tape.)
So if you create a perl script, place it somewhere in $PATH, and set its execute permission a running shell will not find it. A full path, perhaps starting with the current directory " . " always works. In tcsh the command to rework the hash of tools is "rehash". Restarting the shell with a new Terminal.app window will do pretty much the same thing. -- Applescript syntax is like English spelling: Roughly, though not thoroughly, thought through.