use List::Util 'shuffle'; my @list = (1..33); my @blue = (1..16); my $y = $#blue;my $i=10;while ($i>0){ @shuffled = shuffle(@list); my @result = sort {$a <=> $b} (@shuffled[1..6]); my $j = int rand ($y+1); push @result,'|'; push @result,$blue[$j]; print "@result\n"; $i--;}