in reply to Programmatic creation of iterated string

Do you mean something like this:
my $s=""; for (1,4,7) { $s .= join(" ", $_ .. $_+2) . "\n";}
For a general K*K, you can do
$K=5; for (1 .. $K*$K) { $s.= ( $_ % $K ? "$_ " : "$_\n"); }