if (defined $outfile) { open OUTPUT, '>', $outfile; select OUTPUT; } # then just use "print"