# adapted from Perl Cookbook sub filteroutput { return if my $pid = open(STDOUT, "|-"); die "cannot fork: $!" unless defined $pid; while() { if(/regex/) { dosomething($_); } print; } exit; #exit forked monitoring process }