in reply to Redirect STDOUT to a $variable

I found that this works: sub print_to_var { my ($m, $v) = @_; local *STDOUT; open(STDOUT, ">", \$v); print $m; return $v; } #returns variable which contains string of $m printed