my @institutions = qw|hospital1 hospital2|; my %seen; $seen{$_}++ foreach @institutions; if (!defined $institution) { $institution_table{"unaffiliated"} ++; } elsif (exists $seen{lc $institution}) { $institution_table{lc $institution} ++; } else { $institution_table{"other"} ++; }