local $SIG {ALRM} = sub {die "alarm"}; eval { alarm (5); system "sleep 10"; alarm (0); }; if ($@ && $@ =~ /^alarm/) { say "Command interrupted"; }