$ perl -wle '$msg = qx/ls -K 2>&1/; print "error: $?"; print $msg' error: 512 ls: invalid option -- K Try `ls --help' for more information.