in reply to foreach problem

Using
use strict;

will help to avoid these kinds of errors.
Cheers!