use strict; use warnings; # get the inputs into an array, one "number" or "n:n" range per array element. # then: my @covered; # an array to track the "coverage" of the inputs # for each input array element { # if the element does not contain ":" # use it as an array index and set $covered[$element] to some value # otherwise # split on ":", sort the pieces numerically and assign to $begin, $end # $covered[$_] = 'some value' for ( $begin .. $end ); # } # Once that's done, the only thing left to do is: my $uncovered = ''; for ( 0 .. $#covered ) { $uncovered .= "$_, " unless ( defined( $covered[$_] )); } $uncovered =~ s/, $/\n/; print $uncovered;