#!/usr/bin/perl -w use strict; $SIG{USR1} = \&handler; $SIG{ALRM} = \&handler; while (1){alarm 5; sleep 100;} sub handler { print "Do work \n"; #your get_message,send_message calls }