open INFILE, "flatFile.csv" || die("Can't read flatFile.csv"); open OUTFILE, ">flatFile.out" || die("Can't open flatFile.out"); $MAX_PARAMS = 11; $THIS_PAGE = "http://mypage.com/new/test.pl?opt_1=FIELD1&opt_2=FIELD2&opt_3=FIELD3&opt_4=FIELD4&opt_5=FIELD5&opt_6=FIELD6&opt_7=FIELD7&opt_8=FIELD8&opt_9=FIELD9&opt_10=FIELD10&ins_company=FIELD0&t=s"; $THIS_DELIMTER = ","; while () { @theseFields = split/$THIS_DELIMTER/; $paramLength = @theseFields; $paramLength == $MAX_PARAMS || warn("expected $MAX_PARAMS parameters, $paramLength parameters found:"); $finalPage = $THIS_PAGE; for ($i = 0; $i < $MAX_PARAMS; $i++) { $finalPage =~ s/FIELD$i/$theseFields[$i]/gi; } print OUTFILE "$finalPage\n"; } close OUTFILE; close INFILE;