close STDOUT; my $output = ""; open(STDOUT, ">", \$output) or die "Can't open STDOUT: $!"; print "test \n";