if($data[$i] =~ /Message Type: /){ $j=$i+13; #This will not work $k=$i+14; #This will not work @details0=split / /, $data[$i]; @details1=split / /, $data[$j]; @details2=split / /, $data[$k]; $txname=$details0[2]; $txtime=$details2[2]; $errorcode=$details1[2]; print OUT "$txname\t\t\t$txtime\t\t$errorcode\n"; }