use File::Tee qw(tee); tee(STDOUT, '>', $outfile) or die ...;