$extflag is set to one in the parent process, but not in the child process. Therefore it stays 0 in the child process and the loop is never terminated. What I don't understand is why have a loop there at all - a simple if (or an unless ($extflag)) would be sufficient to limit the contents of the block to the child process(es). Also, try to keep your indentation consistent with {} nesting level - it might make it easier to understand (and might even be the
real problem ;)