use constant CHUNK => 8; for (my $x = 0; $x < length($str) / CHUNK; ++$x) { print substr($str, $x * CHUNK, CHUNK), "\n"; }