#! perl -lsw use strict; my @reps = map{ sprintf '%05d', $_ } 0 .. 20; while() { my $n=0; # redundant /e option removed # per [Abigail-II]'s comment below. s/\d{5}/$reps[$n++]/g; print; } __DATA__ 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000xxxx00000xxxxx00000xxxx00000xxxxx00000xxx00000xxx00000xx00000xxx00000x00000x00000 #### c:\test>234342 00000000010000200003000040000500006000070000800009000100001100012000130001400015000160 00000xxxx00001xxxxx00002xxxx00003xxxxx00004xxx00005xxx00006xx00007xxx00008x00009x00010