foreach my $itemIndex (1 .. $items->Count) { my ($body) = $items->Item($itemIndex)->Body =~ /MessageBody>(.*)<\/Mess/s; if ($body !~ /\S/) { die "Some appropriate error on index $itemIndex."; } CACHE_CHECK: foreach my $cachedItem (@cache) { my $compare = $cachedItem->[0]; my $len = length($body) > $length($compare) ? length($body) : length($compare); if (distance($body, $compare) / $len < $threshold) { @toBeMoved[$itemIndex, $cachedItem->[1]] = (1, 1); last CACHE_CHECK; } } }