my $i = 1; while () { ... s/\b(XP)\b/$1 . ' (' . $i++ . ')'/eg; print; }