#! perl -slw use strict; my $result = "\0" x 100; while (my ($start, $end) = split ' ', ) { substr($result, $start, $end - $start + 1) = 1 x ($end - $start + 1); } my (@results, $start); for (0 .. length $result) { my $c = substr($result, $_, 1); next if not $start and $c ne '1'; $start = $_ if $c eq '1' and not $start; next if $start and $c eq '1'; push @results, [$start, $_-1]; $start = undef; } print map{local $"='-'; "[@$_] "}@results; #!" __END__ 17 19 34 39 26 29 53 57 43 47 58 59 40 45 30 33 20 24 10 15 6 9 1 4 35 45 7 15