I'm assuming $line7 contains the excessive amount of data that you've posted. In the script below, I've used a representative sample. For future posts, please do the same.

You haven't shown how you've extracted that data. Ensure $line7 actually contains the data you think it does (i.e. print "$line7\n";).

In the script below, I've simply captured everything that isn't a double-quote between '/translation="' and '"' then removed all the extraneous whitespace.

#!/usr/bin/env perl -l use strict; use warnings; my $line7 = ' ... /db_xref="GI:2735715" /translation="MLSFVDTRTLLLLAVTLCLATCQSLQEETVRKGPA +GDRGPRGER GPPGPPGRDGEDGPTGPPGPPGPPGPPGLGGNFAAQYDGKGVGLGPGPM +GLMGPRGPP YASQNITYHCKNSIAYMDEETGNLKKAVILQGSNDVELVAEGNSRFTYT +VLVDGCSKK TNEWGKTIIEYKTNKPSRLPFLDIAPLDIGGADHEFFVDIGPVCFK" exon 2432..2501 ... '; my $re = qr{/translation="([^"]+)"}; my ($extract) = $line7 =~ $re; $extract =~ s/\s+//g; print $extract;

Output:

MLSFVDTRTLLLLAVTLCLATCQSLQEETVRKGPAGDRGPRGERGPPGPPGRDGEDGPTGPPGPPGPPGP +PGLGGNFAAQYDGKGVGLGPGPMGLMGPRGPPYASQNITYHCKNSIAYMDEETGNLKKAVILQGSNDVE +LVAEGNSRFTYTVLVDGCSKKTNEWGKTIIEYKTNKPSRLPFLDIAPLDIGGADHEFFVDIGPVCFK

Update: From looking at other posts in this thread, it would seem possible that your initial problem (i.e. before you even start performing any matching) could be extracting the data you want. If that's the case, open a filehandle to your data file and populate $line7 as I've shown below. As you'll see, once you've done that, the rest of the code hasn't changed and the output is identical.

By the way, is there some significance to the $line7 variable name? If not, I'd pick something more meaningful.

#!/usr/bin/env perl -l use strict; use warnings; my $line7 = ''; my $re = qr{/translation="([^"]+)"}; while (<DATA>) { if (/^\s+\/translation=/ .. /^\s+exon/) { $line7 .= $_; } else { $line7 ? last : next; } } my ($extract) = $line7 =~ $re; $extract =~ s/\s+//g; print $extract; __DATA__ ... /db_xref="GI:2735715" /translation="MLSFVDTRTLLLLAVTLCLATCQSLQEETVRKGPA +GDRGPRGER GPPGPPGRDGEDGPTGPPGPPGPPGPPGLGGNFAAQYDGKGVGLGPGPM +GLMGPRGPP YASQNITYHCKNSIAYMDEETGNLKKAVILQGSNDVELVAEGNSRFTYT +VLVDGCSKK TNEWGKTIIEYKTNKPSRLPFLDIAPLDIGGADHEFFVDIGPVCFK" exon 2432..2501 ...

Output:

MLSFVDTRTLLLLAVTLCLATCQSLQEETVRKGPAGDRGPRGERGPPGPPGRDGEDGPTGPPGPPGPPGP +PGLGGNFAAQYDGKGVGLGPGPMGLMGPRGPPYASQNITYHCKNSIAYMDEETGNLKKAVILQGSNDVE +LVAEGNSRFTYTVLVDGCSKKTNEWGKTIIEYKTNKPSRLPFLDIAPLDIGGADHEFFVDIGPVCFK

-- Ken


In reply to Re: Help to build a REGEXP by kcott
in thread Help to build a REGEXP by Anonymous Monk

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.