use strict; use warnings; # @data contains the (chomped, lower-cased) entries # from a 70K dictionary file (2076 words beginning with 'j') my $count; # Or whatever: this can check algorithm validity foreach my $item ( @data ) { compare( $item, $_ ) and $count++ for @data; } print $count; sub compare { return 0 unless length $_[0] == length $_[1]; my $diff = 0; for ( 0 .. length $_[0] ) { $diff++ if substr( $_[0], $_, 1 ) ne substr( $_[1], $_, 1 ); return 0 if $diff > 1; } return 1; }