If it were on a local machine I'd suggest waiting for the other process, but that's not really an option in this case (unless you can wait for the local process? I don't know how P::FM works in any detail, nor how you're set up, so this might be totally useless). Looking at the problem as a whole, rather than the specific solution you've already tried, you might want to change your remote process to send an acknowledgement of some kind back at you when it's done—it requires a little more coding and a little more network traffic, but it seems likely to me that it would work, which appears to be an advantage over the current approach.
If God had meant us to fly, he would *never* have given us the railroads.
--Michael Flanders