my $length = 3; my $data = 'aaabbbcccdddeeefffggghhh'; my @chunks = unpack("(A$length)*", $data); print "$_\n" for @chunks;