for my $itemIndex (1..$items->Count) { my $didWeMove = 0; (my $body) = ($items->Item($itemIndex)->Body =~ /MessageBody>(.*)<\/Mess/s); if ($body eq " ") { die "\nError: Found a message not in the proper format. (No tag)"; } foreach $letterArray (@letterCache) { my $letter = @$letterArray[0]; my $len = (length($body)>length($letter)) ? length($body) : length($letter); if (distance($body, $letter)/$len < $threshold) { push(@toBeMoved, $itemIndex); #If we found one, push the index onto the list... push(@toBeMoved, @$letterArray[1]); #...and push the original onto the list... $didWeMove = 1; #And set this to true. } } if (!$didWeMove) { #If we did not find a match, this is a unique email (so far) push (@letterCache, [$body, $itemIndex]); }