#!/usr/bin/perl -w use strict; my ($string, $count); while(){ 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