#+begin_src perl :results output drawer use strict; use 5.026; my $output; do { open( my $fh, q{>}, \$output ) or die "Problem redirecting to scalar: $!\n"; local( *STDOUT ) = $fh; ## pretend this bit is in some 3rd party module you can't modify printf( "This should go %s", qq{elsewhere} ); }; say qq{\$output is '$output'}; #+end_src #+RESULTS: :results: $output is 'This should go elsewhere' :end: