foreach (@hlines) #each line from file1 was saved to this array. { $xh= substr $_,31,8; $yh= substr $_,40,8; $zh= substr $_,48,8; foreach $pline (@plines) #ditto, each line from file2 saved to this array { $x1= substr $pline,31,8; #using $_ here instead of $pline aborts execution due to compile errors. $y1= substr $pline,40,8; $z1= substr $pline,48,8; $r2=((&square($xh-$x1))+(&square($yh-$y1))+(&square($zh-$z1))); $r=sqrt($r2); print "$i. $r2 and square root is $r\n"; } }