use List::Util qw( shuffle ); my @selection = (shuffle(@nums))[0..7];