# Assume @all_pics to be your array my %seen; @all_pics = grep !$seen{$_}++, @all_pics; #### my $pic = splice @all_pics, rand @all_pics, 1;