in reply to strings as placeholders

my @ranges = qw(1..4 5..8 9..12 13..16 1..8 9..16 )
That's not going to do what you want (and you forgot a semi-colon on the end). I think you want:
my @ranges = ([1..4],[5..8],[9..12],[13..16],[1..8],[9..16]); foreach my $range (@ranges) { foreach (@$range) {...
As for your problem, I'm not sure if I understand it, but my guess is to go through the range a first time and check for 1's, and skip to the next iteration if there's any one's.