#loop from your first script: while ( my $hr = $csv->getline_hr( *DATA ) ) { my $nr = $hr->{'ID'}; $nr=~ s/12/Sun/; # neither the g nor the loop are necessary $nr=~ s/17/Moon/; my $name = $hr->{'NAME'}; # only one value in column NAME of this line my $ind = $hr->{'INDICATOR'}; my $val = $hr->{'VALUE'}; my $low = $hr->{'CI_LOW'}; my $high = $hr->{'CI_HIGH'}; if ($csv->combine ( $nr, $name, $ind, $val, $low, $high)) { print $csv->string, "\n"; } else { print "combine () failed on argument: ", $csv->error_input, "\n"; } }