# If you want to output to STDOUT and to the file, # create a handle which may point to STDOUT. if ($filename) { open(FILE, '>', $filename) or die("Can't open $filename: $!\n"); } else { open(FILE, ">&STDOUT"); or die("Can't dup STDOUT: $!\n"); } print FILE (...); # Goes to file if one was specified, else STDOUT. print(...); # Goes to STDOUT.