in reply to
search and replace with serialized answers
this seems to work pretty well for what you want to do
cat bla | perl -pe '$a=++$a%5;$b=$a+1;s/\n/$b\n/'
Comment on
Re: search and replace with serialized answers
Download
Code
In Section
Seekers of Perl Wisdom