$line =~ s/,//g; # or, another way to get the same result: $line =~ tr/,//d; #### @widths = (3,6,9,2,3,2,3,3,1,2,6,39); # how to break up the original fixed-width data record: while () { my @out = (); for my $w (@widths) { push @out, substr( $_, 0, $w ); #pull off a record $_ = substr( $_, $w ); # remove it from $_ } print NEW join( ",", @out ), "\n"; } close OLD; close NEW; # in a different script now, but with the same values for @widths: # how to check field widths if/when NEW file has been "corrected" open( NEW, ... ) # read the formatted data open( FIXED, ">...) # re-write the old format with new content while () { chomp; my $out = ""; my @val = split /,/; die "bad field count at line $.\n" unless (@val == @widths); for my $i (0..$#widths) { die "bad data at line $., column $i: $val[$i] (not $widths[$i] characters)\n" unless ( length( $val[$i] ) == $widths[$i] ); $out .= $val[$i]; } print FIXED "$out\n"; }