while(...){ ... $type{$_}++; ## increasing the counting as you see needed string ... }