#!/usr/bin/perl @callout = qw( echo foo ); open(my $old_stdout,">&STDOUT"); close(STDOUT); my $stdout; open(STDOUT,">",\$stdout); my $system_return_value = system(@callout); close(STDOUT); open(STDOUT,">&",$old_stdout); close($old_stdout); print "captured: $stdout\n"; # debug unless ( $system_return_value == 0 ) { #... do some stuff, look at return code (shift by 8), # print stdout/stderr of # failed command to log, etc, etc. }