perl -pe's/(?<=test)/ $state++ % 5 + 1 /e' [download]
In reply to Re: search and replace with serialized answers by jwkrahn in thread search and replace with serialized answers by TheBigAmbulance