my $count = 0; while () { s/^"\d+"$/'"' . ++$count . '"'/e; print OUT; } #### % perl -i.bak -pe 's/^"\d+"$/q(").++$count.q(")/e' myfile