The first thing everyone in this thread needs to realize is that '>' is not the separator you want to look for. That's because you don't care what character marks the beginning of every entry, rather you care what character marks the end of every entry. The end of every entry is marked by the string "\n\n", so you should use that has your input line terminator. Remember, ruby uses "\n" for the input line separator by default, which means that when you read a file using IO#each, ruby reads lines--where the end of a line is marked by a newline. However, you can change the input line separator to the string "\n\n" (or any other string): $/ = "\n\n" Once you have an entry, then you just need to do a little housekeeping and remove some "\n" characters. require 'stringio' str =<<ENDOFSTRING >gi|329295464|ref|NM_2005745.3Acc1| Def1 zgc:65895 (zgc:65895), mRNA AGCTCGGGGGCTCTAGCGATTTAAGGAGCGATGCGATCGAGCTGACCGTCGCG >gi|456299107|ref|NM_2342343.3Acc2| Def2 zgc:65895 (zgc:65895), mRNA GTCGCTGGGTCGAAAAGTGGTGCTATATCGCGGCTCGCGTCGATGTCGCGATG CGTGCGCGCGAGAGCGCGCTATGATGAAAGGATGAGAGAG >gi|3542945647|ref|NM_7453343.5Acc3| Def3 zgc:65895 (zgc:65895), mRNA CGTGCGGGGABCCGTACGTGCCGTGGGGGTTTAATAGCGCGCCATCTGAGCAG TTAGTCGCTGACGCATGCACG ENDOFSTRING input = StringIO.new(str) #Now input is just like a File input.each(sep = "\n\n") do |para| buffer = '' lines = para.split("\n") buffer << lines.shift << "\n" lines.each do |line| buffer << line end puts buffer puts "-" * 20 end p $/ --output:-- >gi|329295464|ref|NM_2005745.3Acc1| Def1 zgc:65895 (zgc:65895), mRNA AGCTCGGGGGCTCTAGCGATTTAAGGAGCGATGCGATCGAGCTGACCGTCGCG -------------------- >gi|456299107|ref|NM_2342343.3Acc2| Def2 zgc:65895 (zgc:65895), mRNA GTCGCTGGGTCGAAAAGTGGTGCTATATCGCGGCTCGCGTCGATGTCGCGATGCGTGCGCGCGAGAGCGCGCTATGATGAAAGGATGAGAGAG -------------------- >gi|3542945647|ref|NM_7453343.5Acc3| Def3 zgc:65895 (zgc:65895), mRNA CGTGCGGGGABCCGTACGTGCCGTGGGGGTTTAATAGCGCGCCATCTGAGCAGTTAGTCGCTGACGCATGCACG -------------------- "\n" Note that specifying the new input line separator as an argument to each() serves to restore the original input line separator once the block has finished--which is a good thing. -- Posted via http://www.ruby-forum.com/.