You can accumulate the current string in a scalar and then print and reset it as soon as you know you'll want to. The code will look a lot like what you have.
I've removed a fencepost error by checking that the > line is not the first.#!/usr/bin/perl -w use strict; my ($string, $count); while(<DATA>){ s/\s//g; next if !$count and /^>/; if (/^>/ and $count) { print $count, ' : ', $string, $/; $string = ''; $count++; next; } $count || $count++; $string .= $_; } print $count, ' : ', $string, $/; __DATA__ > Seq 1 (two lines) AAAAAAAAAAAAA CCAAAAAAAAAAA > Seq 2 (two lines) AAAAAAAAAAAAA AAAAAAAAAAAAA > Seq 3 (one line) TTTTTTTTTTTTAACTGAAGATTCGC
Having a leading marker instead of a trailing one makes this a little awkward.
After Compline,
Zaxo
In reply to Re: How to avoid using array in concatenating string of multiple lines
by Zaxo
in thread How to avoid using array in concatenating string of multiple lines OR How To Read FASTA
by monkfan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |