in reply to how to so this string replacement elegantly

It's not too clear just what kind of transformations you want to do, but the data looks like the fields are different enough to each take completely different treatment.

How about making an array of subroutines, each handling the transformations for the field with the corresponding index?

my @xforms = ( sub { $_[0] = $_[0] || 1; }, sub { # dummy, no transform $_[0]; }, sub {1}, sub { $_[0] =~ s/foo/bar/; $_[0]; }, sub {1}, sub {1}, sub {1}, sub {1}, ); while (<DATA>) { my @tmp = split ','; for (0 .. $#tmp) { $xforms[$_]->($tmp[$_]); } print join ',', @tmp; }
So long as you don't use code tags, I can't tell where your data lines end or guess what you might want to do to them.

After Compline,
Zaxo