$ cat test.pl use 5.18.2; use warnings; use Capture::Tiny "capture"; my ($out, $err, $ext) = capture { # Local scope print STDERR "Output to STDERR\n"; warn "Warn!\n"; system "ls /tmp/bjfgerfbv"; qx{ls /tmp/jhgbejgrbe}; }; # Previous scope print STDERR "Hello world\n"; system "ls /tmp/foobar2"; print STDERR "OUT: $_\n" for split m/\n/ => $out; print STDERR "ERR: $_\n" for split m/\n/ => $err; $ perl test.pl Hello world /bin/ls: cannot access /tmp/foobar2: No such file or directory ERR: Output to STDERR ERR: Warn! ERR: /bin/ls: cannot access /tmp/bjfgerfbv: No such file or directory ERR: /bin/ls: cannot access /tmp/jhgbejgrbe: No such file or directory