... #use List::Util 'shuffle'; use List::Util 'sample'; ... #my @playlist = (shuffle @all_files)[0 .. $list_length - 1]; my @playlist = sample $list_length, @all_files; #print "$_\n" for sort @playlist; print "$_\n" for @playlist; ... #### ken@titan ~/tmp/pm_11150231_dir_rand_select $ ./rand_select_files_sample.pl /home/ken/tmp/pm_11150231_dir_rand_select/inc2/n.x /home/ken/tmp/pm_11150231_dir_rand_select/a.x /home/ken/tmp/pm_11150231_dir_rand_select/c.z ken@titan ~/tmp/pm_11150231_dir_rand_select $ ./rand_select_files_sample.pl /home/ken/tmp/pm_11150231_dir_rand_select/inc1/j.z /home/ken/tmp/pm_11150231_dir_rand_select/c.z /home/ken/tmp/pm_11150231_dir_rand_select/inc1/h.x ken@titan ~/tmp/pm_11150231_dir_rand_select $ ./rand_select_files_sample.pl /home/ken/tmp/pm_11150231_dir_rand_select/inc1/j.z /home/ken/tmp/pm_11150231_dir_rand_select/c.z /home/ken/tmp/pm_11150231_dir_rand_select/a.x