Running perl shell script from AppleScript on Mojave
The issue is that you need to quote file paths for unix, using the quoted form of command in AppleScript.  In other words, line three should read:

set theFolder to quoted form of (POSIX path of myFolder)


The problem happens because Mac variables can legally contain special characters — like spaces and single quotes — that the unix system uses. So, if you were to choose a folder named "My Test Folder", AppleScript would return its posix path as /Users/username/My Test Folder, but the command line invoked by do shell script would read that as three separate arguments, not one single file path. The quoted form of command quotes and escapes any unix special characters in the line of text so that they are not interpreted as special characters by the shell.