Yes, there is a trick, you can just localize the '$/' variable, set it to '>', and loop through your data. I haven't seen your actual data, but I made a few assumptions, and came up with the code below, which I believe is memory efficient.
use strict; use Data::Dumper; my @seq; # array of sequences my %seq; # hash lookup of sequences based on id's { local $/ = '>'; while (<DATA>) { s/^>//g; # strip out '>' from beginning s/>$//g; # and end of line next if !length($_); # ignore empty lines my ($header_info) = /^(.*)\n/; # capture the header s/^(.*)\n//; # and strip it out my @rec = split /\|/, $header_info; s/\n//mg; # join the sequence strings push @rec, $_; # make sequence the last element push @seq, \@rec; # push into array of sequences $seq{$rec[1]} = \@rec; # or store in a hash lookup } } print Dumper(\@seq); print Dumper(\%seq); __DATA__ >gi|2695845|emb|Y13255.1|ABY13255 Acipenser baeri mRNA for immunoglobu +lin heavy chain, clone ScH 3.3 TGGTTACAACACTTTCTTCTTTCAATAACCACAATACTGCAGTACAATGGGGATTTTAACAGCTCTCTGT +ATAATAATGA TACCCCCGCGACCTTCTCGTGGACTGATCAATCTGGAAAAGCTTTT >gi|2695846|emb|Y13255.1|ABY13255 Acipenser baeri mRNA for immunoglobu +lin heavy chain, clone ScH 3.3 TGGTTACAACACTTTCTTCTTTCAATAACCACAATACTGCAGTACAATGGGGATTTTAACAGCTCTCTGT +ATAATAATGA TACCCCCGCGACCTTCTCGTGGACTGATCAATCTGGAAAAGCTTTT

In reply to Re: Refomating a large fasta file... by Roger
in thread Refomating a large fasta file... by bioinformatics

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.