use strict; use warnings; my $timeout_msg = "Timeout after 3 seconds!\n"; my $t = time; my $pid; eval { local $SIG{ ALRM } = sub { die $timeout_msg }; alarm 3; $pid = system 1, 'timeout /t 6 > nul && echo Good Morning!'; waitpid $pid, 0; alarm 0 }; if ( $@ ) { die $@ unless $@ eq $timeout_msg; print $@; kill 'KILL', $pid } print time - $t, "\n";