use FileHandle; my $log = 0; print "Do you want to log to a file?"; my $resp = ; if ($resp =~ /^y/i) { my $fh = new FileHandle; my $filepath = "c:\\stdout.txt"; $fh->open(">> $filepath") || die "could not open log file $filepath"; select $fh; } # # this will go to log file if $resp was y # print "Holla!\n";