sub find_paring() { my $wp = $_[0]; foreach my $bp (&shuffle keys %{$matches_remaining{$wp}}) { if (exists $matches_remaining{$bp}{$wp}) { delete $matches_remaining{$wp}{$bp}; delete $matches_remaining{$bp}{$wp}; return ($wp, $bp); } } # Else return undef undef; }