for my $first (@group1) { for my $second (@group2) { for my $third (@group3) { for my $fourth (@group4) { # Assume fixed size = 2 # $first, $second and $third repeat here for each member in @group4 # $first, $second pairings happen multiple times } } } }