use Expect; my $timeout=5; foreach my $i (1..20) { my $exp = Expect->spawn("./unreliable.pl") or die "Cannot spawn unreliable process $!\n"; $exp->expect($timeout, [ timeout => sub { print "Process timed out.\n"; } ] ); }