in reply to Re: Re: Re: Finding dictionary words in a string.
in thread Finding dictionary words in a string.

Not going to chime in with regards to the array in memory, but with regards to the output difference, just store the word in uppercase, as well. Also, don't forget to Code Smarter. Use index, instead of matching with a regex. That should provide the same functionality with nice speed gains.
#!/usr/bin/perl use strict; use warnings; my $sw = lc shift or die "search word required\n"; my $count = 0; open WORDS, "/usr/share/dict/words" or die "can't open words file\n"; while (<WORDS>) { chomp; printf "%3d %s\n", ++$count, $_ if index($sw,lc $_) > -1; } close WORDS;