in reply to calling problem in script
I think the problem lies here.
Why do you think that?
Perl would tell you where the problem lies if you used warnings and diagnostics.
Most likely, you want to (re)read perlop