BTW Use of uninitialized value in print at ./hw3.pl line 30, <STDIN> line 9 is a warning, not an error. It simply warns you that a variable has not been initialized (=undef). That can be intentional, but often indicates a programming error like, when not using strict, a typo. As others pointed out, make a habit of adding use strict in your programs.