open(my $fh, 'cmd-to-run 2>&1 |') or die "open error: $!"; while (<$fh>) { # print $_ via your $tee here } close($fh) or die "close error: $!";