in reply to A TRUE-once variable

A join is the right thing to use. Your grep/map thing looks bad because you're trying to do too much at once.
sub with_no_map { my @lines; while <DATA> { chomp; # removes trailing newline next unless /\S/; # skips blank lines @values = split /;/; # gets individual records @values = map {quotrim($_)} @values; # quote vals # normalize number of values by padding with NULL if (scalar(@values) == 3) { splice(@values, 2, 0, 'NULL'); } my $values_group = '(NULL, ' . join(',', @values) . ')'; push @lines, $values_group; } return join(",\n", @lines); }
Untested, but hopefully you get the gist.