use IO::Handle; use IO::File; my $out = IO::File->new('output.txt', 'w') or die $!; STDOUT->fdopen($out, 'w') or die $!; print "hello, world!"; #### use IO::Handle; use IO::Scalar; my $data = ''; my $out = IO::Scalar->new(\$data) or die $!; STDOUT->fdopen($out, 'w') or die $!; print "hello, world!";