if ($query{submit} eq "PDF") { open STDOUT, ">tempfile.html" or graceful_exit("can't open file"); } #### if ($query{submit} eq "PDF") { open OUTPUT, ">tempfile.html" or graceful_exit("can't open file"); } else { open OUTPUT, '>STDOUT'; # I know this is wrong }