#!/usr/bin/perl use warnings; use strict; use IPC::Open3; my $pid = shift || $$; my $pid1 = open3(\*WRITE,\*READ,0,"/bin/sh"); #if \*ERROR is false, STDERR is sent to STDOUT while(1){ print WRITE "ps -o rss= -p $pid\n"; select(undef,undef,undef,.1); my $size = ; #do your checks here and do whatever print "$size"; }