use strict; use warnings; my @final; my $item; my @list = (2, 1, 4, 3, 8, 5); #already selected from array #image another loop someplace else that is pushing into @list for (1 .. 5) { #getting 5 numbers not on the list above... my $find = int rand (10); #my "array" I am picking from is 0-10 #below this is my attempt to solve my problem my $found_flag = 0; foreach my $item ( @list ) { if( $item eq $find ) { $found_flag = 1; last; } } if( $found_flag ) { print "Found $find.\n"; until ( $find != $item ) { $find = int rand (10); } } #I tried to basically say # if (the item is already in the array) { # pick a value until it is not found in the array # } push @final, $find; } print "@final \n";