use warnings; use strict; #### my %type; @type{qw(AB AC AD AE FG)} = (0) x 5; #### ##then you have something like this: $VAR1 = { 'AC' => 0, 'AE' => 0, 'FG' => 0, 'AB' => 0, 'AD' => 0 }; #### while(...){ ... $type{$_}++; ## increasing the counting as you see needed string ... }