#!/usr/bin/env perl use strict; use warnings; my $command = 'echo foo'; my $stdout = `$command`; print "STDOUT: $stdout"; $command = 'ls some-missing-file'; my $stderr = `$command 2>&1 >/dev/null`; print "STDERR: $stderr"; print "\nNow display stdout while command runs:\n"; $command = 'echo bar;sleep 3; echo baz'; open my $pipe, "($command) |"; while (<$pipe>) { print; } close $pipe