Perl: Split string into sets of characters without delimiter

Hi,

I would like to split a string into sets of characters without the help of a delimiter. For example if I have a random string like this one:
my $str = "1101111000110000001110110111";
I'd like to split it into sets of four characters, so 0-3, 4-7, 8-11, etc and then process them in a loop like foreach.

How can I do this?
php-newbieAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ozoConnect With a Mentor Commented:
my $str = "1101111000110000001110110111";
for( unpack"(a4)*",$str ){
   print;
}
0
 
ozoConnect With a Mentor Commented:
while ( $str=~/(....)/g  ){ print $1; }  
0
 
php-newbieAuthor Commented:
awesome, thanks!!!!!!!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.