Geez. One can only hope that this "emergency message" doesn't mean something like "reactor coolant low"!
To make this into a single process, you will need to determine whether or not the socket for the device has a line for you to process in it or not. I think that you will need IO::Socket. This sort of thing would be done in what is called a "select server". Don't read from the socket unless you know that it has something to say.
I think this psuedo code would be fine in your application.
# open file handles for reading and reporting
# set $since_report_secs (seconds) = 0
while (sleep (1))
{
my $emergency = check_for_emergency();
if ($emergency)
{
do something;
}
report_awake_status();
}
sub check_for_emergency
{
while (device port ready to read)
{
read line and check it for "emergency"
return 1 if emergency;
}
return 0; # "no error";
}
sub report_awake_status
{
$last_report_time++;
if (more than 30 minutes)
{
send awake message, set counter back to zero
}
}
The above code essentially sets up a "polling loop". This is not as efficient as it "could be". But the logic for a simple single process is simple and I think that you will find that code like this doesn't take much CPU time.