in reply to keeping context in a loop

use warnings and strict. If I turn on warnings, I get this message:
Name "main::uwordi" used only once: possible typo at...

Fix that first, then if you still have problems, try to reduce your code to something we can run -- without reliance on external files or databases.