use strict; use warnings; my @cols = qw (5 11); while () { chomp; my $row = ''; my $start = 0; for my $cs (@cols) { my $offset = $start; my $length = $cs-$start; $row .= substr($_, $offset, $length) . ','; $start = $cs; } $row .= substr($_, $start); print "$row\n"; } __DATA__ 12345678901234567890 abcdefghijklmnopqrst