use strict; # use this always. no excuses. use warnings; # same with this. my @params; my @charam; my @actual; # declare all your variables!! my $i; my $j; # declare all your variables!! open FILE, "params.txt" or die "unable to open\n"; for($i=1,$j=1; ; $i++, $j++) { chomp; (@params[$i], @charam[$j]) = split(':'); # use $i and $j here, not i and j!!! $actual[$i]=$charam[$j]; # better use $actual[$i] instead of @actual[$i] (same on line above!) print "inside $actual[$i]\n"; } print "out side @actual\n"; # it works, but gives an error as $actual[0] is undefined close(FILE);