Here's one way to do it, using the same logic you've used:
use strict;
use warnings;
use List::Util qw/sum/;
my $host = 'db';
my @redAlert = ("db");
my @orangeAlert = ( "c", "sm" );
my %status =
( 'status_history' => { 'status' => [ 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 ]
+ } );
my $statusHist01 = sum @{ $status{status_history}{status} }[ 0 .. 1 ]
+;
my $statusHistTot = sum @{ $status{status_history}{status} };
if ( $host ~~ @redAlert
or ( $host ~~ @orangeAlert and $statusHist01 == 2 )
or $statusHistTot == 3 )
{
print "We've got a winner!";
}
The alerts are contained in arrays, so Perl's (v5.10+) smart operator (~~) can be used to check whether the value of $host is an element of either array. List::Util's sum is used to sum the relevant values from the status list.