in reply to Term::Readkey and waitpid

The ReadKey(0) in your second example blocks, which means that your program sleeps until a key is read from standard input. The waitpid() call is not executed until a key is pressed, which can happen long time after the child terminates.

Your first snippet takes so many cpu cycles because both calls are non-blocking, which means that the program keeps calling them until one of the events they poll for happens, with the added disadvantage of slowing down execution of the child you're waiting for.

In order to fix this you could have your program sleep for some milliseconds on each iteration (see perl functions sleep and select) or you could install a handler for the CHLD signal, which is just a subroutine that gets called whenever a child of your process terminates (see the perlipc manpage).