I'm curious, since i haven' done anything like this with switches, i know a little and thus a few simple questions.
Are you trying to create two hashes and see how much of one matches the other? Meaning is there a reason why one while is inside the other one?
Thing that is strange to me also is that you seem to replace entire hash in both hashes within each while loops pass (although this might come from my limited understand of how to pass values into hash) or is this intentional?