use POSIX qw/floor/; local $/= '==='; my @allquestions = ; my @questions; for (1..$maxcount){ my $idx = floor rand @allquestions; push @questions, splice @allquestions, $idx, 1; } return @questions;