#! /usr/bin/env perl use strict; use warnings; $SIG{INT} = \&interrupt; #open LOGFILE, "|-", "tee some_file.out"; open LOGFILE, ">", "/tmp/log.txt"; LOGFILE->autoflush(1); select LOGFILE; print "fileconsole!\n"; print "pause\n"; my $in = ; select STDOUT; print "console1\n"; die; sub interrupt { print "Caught a control c!\n"; die; } END { if(fileno(LOGFILE)){ print "close logfile\n"; close(LOGFILE) or warn; } }