my $x = "0123456789abcdef" x 4 . "XXX";
my $chunksize= 16;
for (my $i=$chunksize*int((length($x)-1)/$chunksize);$i;$i-=$chunksize
+) {
substr($x,$i,0)=" ";
};
print $x;
And if you really want to use split Or you might still want a regular expression:
join " ",$x=~/(.{1,$chunksize})/g
Update to my first codesnippet: Thanks to oshalla's comment above I noticed that I also had a space too much when the string has a length being a multiple of chunksize.
s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
|