if( @ARGV ){ $SIG{INT} = \&exit_gracefully; for(1..10){ warn "called sleeping $_"; select undef, undef, undef, 0.5; } exit 1; } else { warn "calling system\n"; system ( $^X, __FILE__ , 'called'); $exit_val = $? >> 8; warn "\n exit_val $exit_val"; } sub exit_gracefully { $SIG{INT} = \&exit_gracefully; print "@ARGV Program interrupted .. \n"; exit (2); } __END__