in reply to Problem while refactoring code into a subroutine (was: subroutines!!!)

To expand further, this problem could've been found immediately. Add the following lines to the top of your program:
use 5.6.0; use strict; use warnings;
If that breaks saying that your perl is not 5.6.0 or higher, do the following:
#!/your/perl/here -w use strict;
You might have a lot of statements saying that "Such'n'such isn't declared". Use my liberally.

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

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

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