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] }