use Capture::Tiny 'capture'; my ($out, $err) = capture { print "Capture this"; might_print_via_XS(); system($^X, '-e', 'print "Capture me too\n"; warn "And this"'); };