############################################################### my $pair_no = 1; foreach my $conn (@input_connections) { print "\rON pair $pair_no"; my @curr_conn = split(/\-/,$conn); ## check if current connection exists my $exists = 1; my $start = $curr_conn[0]; my $end = $curr_conn[1]; ## first number in pair is larger than second, reverse them if ($curr_conn[0] > $curr_conn[1]) { $start = $curr_conn[1]; $end = $curr_conn[0]; } ## ** Ideally I want to do away with this loop ** ## for ($start..$end) { if ( not defined $used_connections[$_] ) { $exists = 0; last; } } if ($exists == 0) { for ($start..$end) { $used_connections[$_] = 1; # I tried something like @used_connections[$start..$end] = 1 , but # it did not seem to work the same as what is in place now. } push @output_connections , $conn; } $pair_no++; } ###############################################################