in reply to To replace the occurence string in perl

You can count the occurrences of each name with a hash and use eval substitution to increment on the go. Like this:

use strict; use warnings; my %count; while (<>) { s{<bib id="CIT-(\w+)-b(0*\d+)">} {"<bib id=\"CIT-$1" . ++$count{$1} . "-b$2\">"}ge; print; }

Incrementing undef will treat it as 0, so when a key is first encountered it will have 1 appended to the name.