## Set the input separator to be '>'; and the output separator to be "\n"' BEGIN { $/ = ">"; $\ = "\n"; } ## read each input record (terminated by the '>' character) into $_ LINE: while (defined($_ = )) { ## Remove the record terminator ('>') chomp $_; ## split the record on whitespace into @F our(@F) = split(' ', $_, 0); ## If the record was empty (the first one always will be with your data), ## then skip to the next record. next unless @F; ## remove the 'length=' prefix from the second field s/length=// foreach ($F[1]); ## replace the 6th field in the array, with the concatenation of itself ## and all the fields that follow it @F[5] = join('', @F[5..99]); ## Then discard all the fields that follow it. ## Ie. truncate the array after the 6th field $#F = 5; ## And print out the fields joined with ','s and prefixed with '>' ## (and ending with a newline. See output separator above.) print '>', join(',', @F); }