my $str; my $io = tie *STDOUT, 'IO::Scalar', \$str; print_monks(); undef $io; untie *STDOUT; # $str now contains the output of the print_monks() function. #### use Some::Module qw(print_blah); my $str; my $io = tie *STDOUT, 'IO::Scalar', \$str; print_blah(); undef $io; untie *STDOUT; # print_blah() prints to stdout.