PERL Fixed Width to CSV based on Input Files <p>EDITED: I'm attempting to create a brief script that calls for an input fixed width file and a file with the start position and length of each attribute and then outputs the file as CSV instead of fixed width. I haven't messed with removing whitespace yet and am currently focusing on building the file reader portion. </p> <p>Fixed: My current issue is that this code returns data from the third row for $StartPosition and from the fourth row for $Length when they should both be first found on the first row of COMMA. I have no idea what is prompting this behavior.</p> <p>Next issue: It only reads the first record in practice_data.txt I'm guessing it's something where I need to tell COMMA to go back to the beginning?</p> <pre><code>while (my $sourceLine = &lt;SOURCE&gt;) { $StartPosition = 0; $Length = 0; $Output = ""; $NextRecord =""; while (my $commaLine = &lt;COMMA&gt;) { my $Comma = index($commaLine, ','); print "Comma location found at $Comma \n"; $StartPosition = substr($commaLine, 0, $Comma); print "Start position is $StartPosition \n"; $Comma = $Comma + 1 $Length = substr($commaLine, $Comma); print "Length is $Length \n"; $NextRecord = substr($sourceLine, $StartPosition, $Length); $Output = "$Output . ',' . $NextRecord"; } print OUTPUT "$Output \n"; } </code></pre> <p><strong>practice_data.txt</strong></p> <pre><code>1234512345John Doe 123 Mulberry Lane Columbus Ohio 43215Johnny Jane 5432154321Jason McKinny 423 Thursday Lane Columbus Ohio 43212Jase Jamie 4321543212Mike Jameson 289 Front Street Cleveland Ohio 43623James Sarah </code></pre> <p>Each record is 100 characters long. <strong>Definitions.txt:</strong></p> <pre><code>0,10 10,10 20,10 30,20 50,10 60,10 70,5 75,15 90,10 </code></pre>