my @data; # Read the lines one by one. while ( $line = <$FH> ) { # split the fields, concatenate the first three fields, # and add it to the beginning of each line in the file chomp($line); my @fields = split(/,/, $line); unshift @fields, join '_', @fields[0..2]; # remove user input commas in fields 7 and 19 $_ = for fields[7,19]; # format DATE and DATETIME fields for MySQL/sqlbatch60 $_ = join '-', (split /\//)[2,0,1] for @fields[14,20,23]; $_ = Time::Piece->strptime($_,'%m/%d/%Y %H:%M')->strftime('%Y-%m-%d %H:%M') for @fields[38,39]; # write the parsed record back to the file push @data, \@fields; }