if ($string =~ /(.*?)u(.*)/s) { my $pre = $1; my $post = $2; for my $index(0..4) { print "$pre$index$post\n"; push(@register_list, "$pre$index$post"); } } is there a way to make it print like 0,1,2,3,4 and not just 1,2,3,4??