Writing a loop to manipulate a script and store it in multiple output files

I have a script where the the 9th line looks like this:

    $filename=sprintf\("250.1chr%d.ped", $N\);

I want to modify this script 1000 times, changing 250.1chr%d.ped to 250.2chr%d.ped, 250.3chr%.ped.......and so on all the way to 250.1000chr%d.ped and store each output in files called

getout.pl.1 through getout.pl.1000. How do I go about doing that? Thanks a lot!

%d works more than once.

my $M, $N;

for($M=1; $M<=1000; $M++)
{
        for($N=1; $N<=22; $N++)
        {
                $name=sprintf("%d.%dchr%d.ped", 250, $M, $N);
        }
}

Why not have a loop in the script that runs 1000 times, instead of making 1000 scripts that do the same thing?

That would work but the thing is I want to have 1000 output files one for each M. How would I go about altering my perl script to obtain that?

Corona wrote the solution to create 1000 output files.

Then for each M, open a different output file.