my @images; # array of filenames my %img; # hash used temporarily $img{$_} = 1 foreach @images; # stick them in a hash @images = keys %img; # now only unique filenames #### @images = grep { ! $img{$_}++ } @images;