my (%symbol,@old,@new); while () { chomp($_ = substr lc($_),0,2); push @old, $_; $symbol{$_}++; push @new, $_ . $symbol{$_}; } print "$_\n" for @new; __DATA__ Line one Line two xxxxxxxxxxx Another line xxxxxxxxxxx Lines end here not xxxxxxxxxxx Fourth line (used to be) Line five Lines end here Lines end here too