#!/usr/bin/perl -w use strict; my @string; # Can I avoid using this array for the task? while(){ s/\s//g; if (/^>/) { push(@string,''); next; } chomp; # concatenate current line # to the last array item $string[-1] .= $_; } print $_+1," : ", $string[$_],"\n" foreach (0..$#string); __DATA__ > Seq 1 (two lines) AAAAAAAAAAAAA CCAAAAAAAAAAA > Seq 2 (two lines) AAAAAAAAAAAAA AAAAAAAAAAAAA > Seq 3 (one line) TTTTTTTTTTTTAACTGAAGATTCGC #### 1 : AAAAAAAAAAAAACCAAAAAAAAAAA 2 : AAAAAAAAAAAAAAAAAAAAAAAAAA 3 : TTTTTTTTTTTTAACTGAAGATTCGC