my $fh = *STDOUT; *STDOUT = undef; foo(); # foo cannot print into the stdout STDOUT = $fh; # restore STDOUT