mainbody { my $index=0; my $input=$mw->getOpenFile(); open FILE, ">$input" or die $!; FILE->autoflush(1); #someother direct printings into file(direct meaning printing into file within this body without calling other functions as below) tie @lines, 'Tie::File', $input or die $!; #somemore direct printings into file #below are functions that get arrays, some indices and prints them into file if($pdb_active) { printtoDataBase(\@exp_beta_alpha,16,6); #below printtoDataBase(\@exp_beta_heavy,32,6); } #other printing functions untie @lines; close FILE; } sub printtoDataBase #the part where the problem occurs { my ($dataArray,$column,$ref_size)=@_; my $index=0; $repeat=10; my @dataArray=@$dataArray; #deref for (;$repeat<($residuenumber+10); $repeat++) { my $size = length $dataArray[$index]; if($size>($ref_size)) { $size=($ref_size); } #refsize tells up to how many digits do the user want the number to be displayed substr($lines[$repeat],($column),($size))= substr($dataArray[$index],0,($size)); $index++; } # above function gets the b-factor numbers in the file found the stated part by the substr }