in reply to Forking problems

You test for undef $pid, which is always false. You probably want !defined $pid.

Also, you say you tried other modules, such as thread. There's no thread module, only threads and Thread.