 <p>Provide the path to your input file as the first command line argument. </p> <p>Note: array indices might be off because I simply took your regex match variables and shifted them down by one (i.e., I didn't test this code).</p> <pre><code>use strict; use warnings; use Text::CSV; my $csv = Text::CSV-&gt;new({ binary =&gt; 1 }) or die Text::CSV-&gt;error_diag; open(my $fh, '&lt;', $ARGV[0]) or die $!; while (my $row = $csv-&gt;getline($fh)) { print "REPLACE INTO student (ID, SIS_ID, STUDENT_NUM, USER_ID, OTHER_USER_ID) VALUES (REPLACE(uuid(), '-', ''), '$row-&gt;[23]', '$row-&gt;[25]', '$row-&gt;[1]', '$row-&gt;[26]');\n"; } $csv-&gt;eof or $csv-&gt;error_diag; close($fh); </code></pre>