use strict; use warnings; use Const::Fast; use Data::Dump; use List::Util qw( shuffle ); const my $N => 10; const my $K => 5; my @range = (shuffle 1 .. $N)[0 .. $K - 1]; dd \@range;