http://www.perlmonks.org?node_id=147981


in reply to Question on s///eg

Here's some not so thouroughly tested code:
my @channels = (1, 1, 0, 1, 1, 1, 0); my $str = join "", @channels; my @range; push @range, join "-", ($-[0], $+[0]-1) while $str =~ m/(1+)/g; print join ",", @range;
prints 0-1,3-5

/prakash

Update: I must add that this may not work for perl versions older than 5.6.0.