sub wait_for_it { $SIG{INT} = \&wait_for_it; sleep(3); } sub writing { local $SIG{INT} = \&wait_for_it; #finish writing }