my @arr_of_names = qw(Mary John Ann); my $txt; my $table = qq||; foreach my $key ( sort(keys %$all_names )) { foreach my $name ( @arr_of_names ) { if($name eq $key) { $txt = "BAD"; $table = $table. qq|"; }else{ $txt = "GOOD"; $table = $table. qq|"; } } $table = $table. qq|
$txt - $key
$txt - $key
|; print $table;