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 } } } } #### A sample to work with: group_1 = A B C group_2 = 1 2 3 4 group_3 = yellow blue green group_4 = tiny small medium large gigantic fixed_size = 2