This is an update to my question. One of the suggestions was that it could not find the .wav file. Therefore I created a directory which had both the Perl to play the sound and the .wav files as well. This worked. As in the case where it did not work, I gave the full path to the .wav file (therefore this was the same in both cases). Therefore the suggestion that it could not find the file was correct but why it works when the wav files are in the same directory is a mystery to me. It would be nice to know.