Your problem description didn't mention how your code fails. So, my first step was to add a line "exit;" right at the start of your code and then try to run the code. I put that exit statement in just to see compile errors. Your code does not come anywhere close to compiling. Perl gives up after the first 34 compile errors!

I would strongly recommend investigating BioPerl. Due to the regex matching capabilities of Perl, Perl excels at DNA bio stuff.

You should be aware that a FORTRAN or C style loop, eg. for ($start=0; $start <= $index_max; $start++) is rare in Perl. While this is legal syntax, the very most common error in programming is the "off by one error". Perl can iterate over an array without using index values.

Again, I recommend that you investigate bioperl. Without any experience or proof, I HIGHLY suspect that parsing a record like shown below is a basic function of that universe of programs and modules.

I recoded part of what I think you are trying to do below.
I did not code the option to eliminate the "sig_peptide" line from @CDS.
See Flipin good, or a total flop? for more details of how to do that.

Without more data like shown below, I am unable to help further.

use strict; use warnings; $|=1; my @CDS; my @ORIGIN; while (my $line =<DATA>) { next unless ($line =~ /\S/); #skip blank data lines push (@CDS,$line) if ( $line =~ /^\s+CDS/ ... $line =~/^\s*[a-z]+/ +); push (@ORIGIN, $line) if ($line =~ /^\s*ORIGIN/...$line !~/\s*\d/); + } print "CDS section:\n"; print @CDS; print "\nORIGIN section:\n"; print @ORIGIN; =PRINTS: ########## a copy from my command line output #### CDS section: CDS 10..1011 /gene="hemoglobin" /codon_start=1 /product="hemoglobin" /protein_id="AAA29796.1" /translation="MHSSIVLATVLFVAIASASKTRELCMKSLEHAKVG +TSKEAKQDG IDLYKHMFEHYPAMKKYFKHRENYTPADVQKDPFFIKQGQNILLACHVL +CATYDDRET FDAYVGELMARHERDHVKVPNDVWNHFWEHFIEFLGSKTTLDEPTKHAW +QEIGKEFSH EISHHGRHSVRDHCMNSLEYIAIGDKEHQKQNGIDLYKHMFEHYPHMRK +AFKGRENFT KEDVQKDAFFVNKDTRFCWPFVCCDSSYDDEPTFDYFVDALMDRHIKDD +IHLPQEQWH EFWKLFAEYLNEKSHQHLTEAEKHAWSTIGEDFAHEADKHAKAEKDHHE +GEHKEEHH" sig_peptide 10..63 ORIGIN section: ORIGIN 1 ggaaccatta tgcactcttc aatagttttg gccaccgtgc tctttgtagc gattg +cttca 61 gcatcaaaaa cgcgagagct atgcatgaaa tcgctcgagc atgccaaggt tggca +ccagc =cut ## Data is abbreviated from https://www.ncbi.nlm.nih.gov/nuccore/M8505 +0.1 ## example URL courtesty of [glycine] __DATA__ COMMENT Original source text: Pseudoterranova decipiens larval cDN +A to mRNA. FEATURES Location/Qualifiers source 1..1353 /organism="Pseudoterranova decipiens" /mol_type="mRNA" /db_xref="taxon:6271" /dev_stage="larval" gene 1..1353 /gene="hemoglobin" 5'UTR 1..9 /gene="hemoglobin" CDS 10..1011 /gene="hemoglobin" /codon_start=1 /product="hemoglobin" /protein_id="AAA29796.1" /translation="MHSSIVLATVLFVAIASASKTRELCMKSLEHAKVG +TSKEAKQDG IDLYKHMFEHYPAMKKYFKHRENYTPADVQKDPFFIKQGQNILLACHVL +CATYDDRET FDAYVGELMARHERDHVKVPNDVWNHFWEHFIEFLGSKTTLDEPTKHAW +QEIGKEFSH EISHHGRHSVRDHCMNSLEYIAIGDKEHQKQNGIDLYKHMFEHYPHMRK +AFKGRENFT KEDVQKDAFFVNKDTRFCWPFVCCDSSYDDEPTFDYFVDALMDRHIKDD +IHLPQEQWH EFWKLFAEYLNEKSHQHLTEAEKHAWSTIGEDFAHEADKHAKAEKDHHE +GEHKEEHH" sig_peptide 10..63 /gene="hemoglobin" mat_peptide 64..1008 /gene="hemoglobin" /product="hemoglobin" misc_feature 696..737 /gene="hemoglobin" /phenotype="'altered epitope (frameshift)'" 3'UTR 1013..1353 /gene="hemoglobin" ORIGIN 1 ggaaccatta tgcactcttc aatagttttg gccaccgtgc tctttgtagc gattg +cttca 61 gcatcaaaaa cgcgagagct atgcatgaaa tcgctcgagc atgccaaggt tggca +ccagc

In reply to Re: Stuck in Perl.. Partial code, but it needs more improvement.. Any suggestions, please? by Marshall
in thread Stuck in Perl.. Partial code, but it needs more improvement.. Any suggestions, please? by cosmin

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.