It has been a long time since I've touched perl, but I might be able to give you a push in the right direction.

I think that a print statement is buffered and doesn't guarantee that whatever printed happens right then. I believe there is a "flush" command that you can run to tell perl "Hey, print now what I've told you to print".