$LINEFORMAT = "A10 A20 A15 A12"; # adjust to your field widths my @fields; # presuming the input is stdin. otherwise, chop it into lines however you like while (<>) { my @line = unpack $LINEFORMAT, $_; if ($line[0]) { # new record if ($fields[0]) { # already have a record read in, print it print join ("|", @fields), "\n"; @fields = (); } @fields = @line; $fields[0] =~ s/^\r//; # strip linefeeds. } else { $fields[$_] .= " $line[$_]" for 0..$#line; } } # print the last record print join ("|", @fields), "\n";