in reply to Require some subtle wisdom

I'm not sure your while condition does what you want.
You probably meant
while (($pw1 ne $pw2) || ($pw1 eq ""))
I'd probably make that
until ($pw1 && ($pw1 eq $pw2))
Just a bit clearer, and correct.