use List::MoreUtils qw(any); my @specials = qw(010 023 025 027 030 043 045 066 097); foreach my $c (qw(col_endow col_gfund col_restr col_total)) if (any { substr($key,0,3) eq $_ } @specials) { $row_data{num_style} = .....