use strict; use warnings; use List::Util qw(shuffle); my @bag = (1 .. 30); # Populate list using the range operator @bag = shuffle(@bag); # Shuffle the bag and store the results my @values = @bag[0..4]; # Get the first 5 results with an array slice print "Your numbers are @values\n";