Try this with your dictionary file. If performance is a problem break into separate files according to word length.
#!perl
use strict;
open IN,'dict.txt' or die "$!";
my %dict=();
for (<IN>){
chomp;
$dict{uc $_}=1;
};
close IN;
for my $word (sort keys %dict){
next unless $word =~ /R/;
my @f = split //,$word;
# loop over each letter
# changing R to S
# to create new word in $w
for my $i (0..$#f){
if ($f[$i] eq 'R'){
my $w = $word;
substr($w,$i,1) = "S";
# check if generated word exists in dict
if (exists $dict{$w}){
print "$word $w\n";
}
}
}
}
poj