use IO::CaptureOutput qw/capture/; my ($stdout, $stderr); capture sub { system($command); } => \$stdout, \$stderr;