in reply to Unexpcted answer

Use use strict; use warnings;! The warnings you are getting (Argument "Y" isn't numeric in numeric eq (==)) should be the tip off. You're using numerical comparison to compare strings. Use "eq" instead.