my $answer = join ", ", map { length $_ } $string =~ /(0+)/g;
- $string =~ /(0+)/g searches for occurances of 0's in your string and returns an array of them
- map { length $_ } ... transforms the array of strings into an array of their lengths (i.e. counts of zeroes)
- Finally, join ", " ... makes a string from this array.
More info:
perlretut,
map,
join.
Edit: and I was a bit late :)