in reply to FOREACH Variables

To clarify, $alarms = "off" is an assignment. Use == to test for numeric equality or eq to test for textual equality.

Always
use strict; use warnings;
Although not related to your question, you are over-using printf, which is (allegedly) slower than print. Perl, and several other languages, has interpolation - when a scalar or array variable is enclosed inside double-quotes it translates to its value. This is one of the advantages of the $ and @ prefixes. So:
printf("%s : %s\n", $alarmd, $alarms );
is better written as:
print "$alarmd : $alarms\n";
and error messages should really be routed to stderr:
print STDERR "ERROR: $error.\n";