#!/usr/bin/perl use strict; use warnings; use feature qw/say/; use 5.10.1; my @rand=(); my $all_the_numbers=int(rand(19)); my $i=0; while ($all_the_numbers<20) { my $number=20-int(rand(30)); push @rand, $number; $i++; last if $i==$all_the_numbers; } say "@rand"; my $h=0; while ($all_the_numbers<20) { for (@rand) { if ($rand[0]<0) { next; #in order to make it skip the negative ones } shift @rand; } $h++; last if $h==$all_the_numbers; } say "@rand";