Why is six in quotes in "if (scalar @row1 == "6")"? You want to compare with the number 6, not the string "6" (which would be converted to a number by ==). The scalar is useless too. == creates a scalar context, so scalar is redundant.