my $str = ''; open my $fh, '>', \$str; print {$fh} 'this will end up in $str'; print "\$str contains: $str\n"; __output__ $str contains: this will end up in $str