use List::Util qw(shuffle); my $n = 10; # use $ARGV[0] or whatever to set $n print join " ", shuffle(1 .. $n);