##
% cat asdf
#!/bin/sh
echo "output to stdout"
echo "output to stderr" >&2
####
% perl -e '$x=`./asdf 2>&1`;print "Captured $x"'
Captured output to stdout
output to stderr
####
$output = `cmd 2>&1`; # either with backticks
$pid = open(PH, "cmd 2>&1 |"); # or with an open pipe
while () { } # plus a read
## ##
% perl -e 'open(F,"./asdf 2>&1|");while($x=){print "Captured $x";}'
Captured output to stdout
Captured output to stderr