#!/usr/bin/perl -w use strict; #$|=1; #see note below... $SIG{'ALRM'} = 'timeout'; alarm(1); while (1){sleep(1);} sub timeout { print "stdout: Alarming!\n"; print STDERR "stderr: Alarming!\n"; exit(0); }; __END__ prints: Note: stderr msg comes first because "autoflush" for stdout wasn't turned on (stdout normally doesn't get "flushed" until program end). $|=1; turns autoflush on. stderr: Alarming! stdout: Alarming!