#! 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