#!/usr/bin/perl -w use strict; my $process = "perl"; my @output; my $kidpid; if ($kidpid = open(PIPE, "-|")) { # Parent process. Read data from the child. @output = ; } else { # Child process. Execute the command. die "could not fork" if !defined($kidpid); exec ("ps", "-ef", "|", "grep", $process) or die "exec failed: $!"; }