perl -i.bak -pe 's/^"\d+"/++$i; qq{"$i"}/e;' file <- Unix perl -i.bak -pe "s/^"""\d+"""/++$i; qq{"""$i"""}/e;" file <- Windows