my %array_of_lists = (1 => \@list3, 2 => \@list4, 3 => \@list899); #my @array_of_lists = (@list3, @list4, @list899); ##Set my hand my $my_pocket = "AcAs"; #printf("\n\n@array_of_lists\n\n"); #My cards my $my_card1 = substr($my_pocket, 0, 2); my $my_card2 = substr($my_pocket, 2, 2); printf("$my_pocket"); #for (my $z = 0; $z <= 100; $z++ #{ for my $a ( 0 .. scalar(keys %array_of_lists)) { #The loop will iterate through each element (hand of current handlist) of the current row and remove any #hand that contains the cards assigned randomly above. for my $b ( 0 .. $#{$array_of_lists{$a}} ) { #If the first card of the random hand above equal the first card in the element I am currently on, then remove the element from this handlist by #splicing it out. Or if the first card of the random hand above equal the second card of the element (hand) I am currently splice it out. if (substr($my_pocket, 0, 2) eq substr($array_of_lists{$a}[$b], 0, 2) || substr($my_pocket, 0, 2) eq substr($array_of_lists{$a}[$b], 2, 2)) { $array_of_lists{$a} = splice(@{$array_of_lists{$a}}, $b, 1); } elsif (substr($my_pocket, 2, 2) eq substr($array_of_lists{$a}[$b], 0, 2) || substr($my_pocket, 2, 2) eq substr($array_of_lists{$a}[$b], 2, 2)) { $array_of_lists{$a} = splice(@{$array_of_lists{$a}}, $b, 1); } } }