$M++; my $step = int ($M / $N); my @s = (map($step * $_, 0..$N-1), $M); my @ranges = map [$s[$_ - 1], $s[$_] - 1], 1..$#s;