#!/usr/bin/perl use strict;
use warnings;
use IO::Tee;
my $logfile_path = '/tmp/tmp_logfile';
my $logfile_h = IO::File->new();
$logfile_h->open($logfile_path, 'a')
or die "Could not open logfile for writing: $!\n";
# now the interesting part
# creates new IO::Tee Object with STDERR and logfile filehandle
my $tee = IO::Tee->new(\*STDERR, $logfile_h);
# prints ERROR to STDERR and logfile
print $tee "Error example!\n";
# the same as above
$tee->print("Error example!\n");