my %seen = (); for my $i ( 0..$#texts[0] ) { next if ( $seen{$texts[$i] ); $seen{$texts[$i] = 1; ... # do stuff with $texts[$i] and $images[$i] } #### my %text_image; @text_image{@texts} = @images; for my $text ( keys %text_image ) { my $image = $text_image{$text}; # do stuff with $text and $image... }