use strict; my $search = "apple"; my $length = 5; #length of the target my $FUZZY = 2; # my $BIG = 10; while(my $a = ){ chomp $a; my $score = $BIG; for(my $i = 0; $i + $length < length($a); $i++){ $score = diff_score($search, substr($a,,$i,$length)); if($score <= $FUZZY){ print "$score: $a\n"; last; } } if($score > $FUZZY){ print "-1:$a\n"; } } # return the number of different letters. sub diff_score{ my ($first, $second)= @_; return $BIG unless length($first) == length($second); my $score = 0; for(my $i = 0; $i < length($first); ++$i){ ++$score if substr($first,$i,1) ne substr($second,$i,1); } return $score; } __DATA__ This is an apple An arple is here What bpple is that What is that What bple is that aplle is not a word #### __OUTPUT__ 0: This is an apple 1: An arple is here 1: What bpple is that -1:What is that 2: What bple is that 1: aplle is not a word