$ perl -wMstrict -e '$SIG{ALRM}=sub{print time." Timeout"};print time." Before\n";alarm 2;sleep 10;print time." After\n"' 1532118865 Before 1532118867 Timeout1532118867 After #### $ perl -wMstrict -e '$SIG{ALRM}=sub{print time." Timeout"};print time." Before\n";alarm 2;$a=time+10;1 while time<$a;print time." After\n"' 1532118963 Before 1532118965 Timeout1532118973 After #### > perl -wMstrict -e "$SIG{ALRM}=sub{print time.qq{ Timeout}};print time.qq{ Before\n};alarm 2;sleep 10;print time.qq{ After\n}" 1532119202 Before 1532119204 Timeout1532119212 After > perl -wMstrict -e "$SIG{ALRM}=sub{print time.qq{ Timeout}};print time.qq{ Before\n};alarm 2;$a=time+10;1 while time<$a;print time.qq{ After\n}" 1532119272 Before 1532119274 Timeout1532119282 After