my $pid = open(PSLIST, " ssh -2 $user\@ $peer ./pslist | ") || die "Remote process list gathering error:\n$!.\n"; while(){ chomp($_); push(@pslist, $_); } close(PSLIST); foreach (@service){ # .. check the existence of a process }