in reply to While loops with if

You're gonna slap yourself ;-)

Leave out the ; after the if, i.e.

if ($usedpw ne m/$pw/) { ... }

Incidently, you have an infinite loop with while (1) {...}, and I don't think it's what you want.

Hope this helps, -gjb-