in reply to convert shell to perl

I found it easy to parse the output of 'top' for things like that.

top is more standard than ps in terms of output layout and input parameters so your script is more portable.