in reply to chopping new line while counting length

A few points about your code spring to mind.

I think this code will do what you want. I have moved the process of getting the data length and printing the item into a subroutine.

use strict; use warnings; my $header = q{}; my $dataAccumulator; while( <DATA> ) { chomp; if( m{^>} ) { printDataItem() if $header; ( $header ) = m{^.(\S+)}; $dataAccumulator = q{}; } else { $dataAccumulator .= $_; } } printDataItem(); sub printDataItem { print qq{>$header length=}, length $dataAccumulator, qq{\n$dataAccumulator\n}; } __DATA__ >IDnumber1 length=350 AGCTG AAGTCGCT >IDnumber2 length=350 AGAACGT ACC >IDnumber3 length=350 AGC ACTTCGCTAACT

The output.

>IDnumber1 length=13 AGCTGAAGTCGCT >IDnumber2 length=10 AGAACGTACC >IDnumber3 length=15 AGCACTTCGCTAACT

I hope this is of use.

Cheers,

JohnGG

Update: Corrected typo.