My first stab:
#!c:/perl/bin/perl -w
use strict;
my %index;
open my $fh, '<', 'dict.dat' or die "open failed: $!";
while (<$fh>) {
chomp;
next if length($_) < 3;
push @{$index{ lc(substr($_, 0, 3)) }}, $_;
}
close $fh;
#print join(', ', map { @$_ } $index{'rad'}), $/;
my $str = 'owijfwapplelaskfiwejfcherryalkfwiofwfblossomowiejf';
for my $i (0 .. length($str)-3) {
for my $j (3..length($str)-$i) {
my $substr = substr($str, $i, $j);
my $index = substr($substr, 0, 3);
next unless exists($index{$index});
for (map { @$_ } $index{$index}) {
print $_, $/ if $_ eq $substr;
}
}
}