use strict; my %hash = ( 'A' => 'on', 'B' => 'on', 'C' => 'off', 'D' => 'off', 'E' => 'off', ); for (keys %hash) { my $result = (exists $hash{$_} and $hash{$_} eq 'on') ? 'OK' : 'KO'; print $result, "\n"; }