The confusion here is that on UNIX, wait the system call usually behaves differently than wait the shell function. The system call waits for any child process to die, returning the PID of the last dead child or -1 if there are no more children to wait for. The shell function normally waits for all children unless given a PID, in which case it waits for just that child.
At the system call level, most UNIX systems also have a waitpid system call that waits for a given child.
Perl follows the UNIX system call model and has both a wait and waitpid function. To wait for all children, you do this:
while (wait() != -1) {}
|