in reply to find words around a word in a file.

Go through the file word by word and remember the previous word. Use a HashofHashes (see perllol) to count your neighbors, i.e.

$count{$thisword}{$previousword}++; $count{$previousword}{$thisword}++;

Do this for every word. That's it. Also you have two options: Handle '.' as a distinct word and words over sentence-boundaries won't be neighbors. Or ignore '.' and words will be neighbors even if they are in different sentences