in reply to Help with a programming problem.

You can find errors by adding
use strict; use warnings;
at the top of the program.