$SIG{'INT'} = 'Int_Handler'; sub Int_Handler { $file = 2; }; $| = 1; $file = 1; while ($file) { print $file; $file = $file == 1 ? 1 : 0; sleep(1); }