my $output; open my $fd, '>', \$output or die "open: $!"; ## print to the $output scalar print $fd "hello\n"; print $fd "world\n"; close $fd; ## use results print $output; __END__ hello world