push @allPairs, grep { defined } ( $fnum, $snum ); # and at another time .. # find half-pairs, which I think is impossible my @halves = grep { scalar @$_ == 1 && ( $_->[0] == $fnum || $_->[0] == $snum ) } @allpairs; # find true pairs with a leading fnum my @matches = grep ( scalar @$_ == 2 && $_->[0] == $fnum } @allpairs # or a trailing fnum my @matches = grep ( scalar @$_ == 2 && $_->[1] == $fnum } @allpairs