## Travel small_str along the length of reference_str - ## 107 matches, 92 exact in 3 seconds my $match=0; for my $i (0..length($reference_str)) { for my $j (0..length($small_str)) { my $ref = substr($reference_str, $i, 10); my @ref_arr = split('', $ref); my $small = substr($small_str, $j, 10); my @small_arr = split('', $small); ## Don't bother if you have less than (9 or) 10 left ;-) last if length($ref) < 10 or length($small) < 10; if ( equal(\@ref_arr, \@small_arr) ) { $match++; print "Found match $match: @ref_arr, @small_arr\n"; } } } print "Final tally - $match\n"; exit(0); sub equal { my ($first, $second) = @_; my $mismatch=0; foreach my $i (0..9) { $mismatch++ if $first->[$i] ne $second->[$i]; return undef if $mismatch > 1; # Bail if you have more than 1 mismatch in the sequence } return 1; }