http://www.perlmonks.org?node_id=793480
Description: apparently FileHandle is deprecated in favor of IO. Here is some code that allows you to write to either STDOUT or a file.
use IO qw(File Handle);

my $io = do 
{
    if (shift) 
    {
    my $tmp = IO::Handle->new;

    die "open failed: $!" unless $tmp->fdopen(fileno(STDOUT),"w");
    $tmp;
    } 
    else 
    {
    my $tmp = IO::File->new('tmp.out', 'w');
    $tmp;
    }
};

$io->print("Some text\n");