in reply to WHILE and DEFINED problem

Both valdez and demerphq have excellent (and overlapping) points. I would like to point out that the proximate issue is the use of defined() and chomp() in the while statement. chomp() never returns an undefined value. Better (though I personally write it as demerphq does) would have been:
while (chomp(my $qline = <QINPUT>)) { # yadda, yadda, yadda }

Though, this will fail to read the last line if it doesn't contain a newline at the end of it. (Similar to the "Incomplete last line" error vi gives you in the same situation.)

Just do what demerphq or valdez (through the link provided) suggest.

------
We are the carpenters and bricklayers of the Information Age.

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.