in reply to incorporate Ctrl+z of unix in Perl code

Unless your stty settings are all messed up very different from typical, C-z is not how you get out of top. As mentioned previously, 'q' will quit top, and batch mode with the number of iterations flag is the "correct" way to do it. See man top at a command shell for details, or check the matrix (pdf - witw) for where hp has them shuffled away at this point in time.

Update (2011-02-03 04:48:30 -0600): Spellcheck.

--MidLifeXis