I think I understand what your problem is. Basically, you're trying to use a regexp match in a loop, creating your own backoff by altering part that was matched. As you found out, that's really not going to work. Although I'm sure there are different ways to approach this, the most natural seems to be to put all your matching into a single regexp. So when you say you want the journal to be no more than 10 words, specify that in your regexp. Then the regexp engine can do the backoff for you, and life should be good. My code below is rather severely rewritten, mostly because that's what it took for me to understand what you were doing.
#!/usr/bin/perl # # parse publications strings # use warnings; use strict; use Data::Dumper; my $TITLE = 'title'; my $YEAR = 'year'; my $START_PAGE = 'start_page'; my $END_PAGE = 'end_page'; my $JOURNAL = 'journal'; my $TYPE = 'type'; my $AUTHORS = 'authors'; my $VOLUME = 'volume'; sub parse_pub ($) { my $string = shift @_; local $_; my %ret = (); @ret{$AUTHORS, $TITLE, $TYPE, $JOURNAL, $VOLUME, $START_PAGE, $END_PAGE, $YEAR} = $string =~ m/^\d+\.\s+ #citation number ([^:]+):\s+ #authors (.+?[.?!])\s+ #title (as short as possible) (\(\w+.?\)\s+)? #type (optional) ((?:\w+[.?!]?\s+){1,10}?) #journal ([\w()]+):\s+ #volume (\d+)-(\d+),\s+ #start page, end page (\d+)\.?$ #year /x or return undef; #not sure the best way to fail gracefully $ret{$JOURNAL} =~ s/\s+$//; return %ret; } my $line = "110. Wunder, E.; Burghardt, U.; Lang, B.; Hamilton, L.: Fa +nconi's anemia: anomaly of enzyme passage through the nuclear membran +e? Anomalous intracellular distribution of topoisomerase activity in +placental extracts in a case of Fanconi's anemia. Hum. Genet. 58: 149 +-155, 1981."; print "$line\n"; my %pub = parse_pub($line); #print Dumper(\%pub); print "J:$pub{$JOURNAL}\n\n";

In reply to Re: Enforcing growth of regex by Eimi Metamorphoumai
in thread Enforcing growth of regex by Hena

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.