I'm interested in it's R-score and protein name. The tricky part is the variable number of occurences of the protein name. ... So I want to fetch ..."

And on fetching the various chunks, what do you need to do with them? How do you want to organize, manipulate or summarize them? Is each "candidate" uniquely identified by the "candidate number"? If so, do you want a simple listing that shows, e.g.

candidate-number R-score [protein-name ...]
What you intend to do with the data is an important issue, because it should determine how you set up the appropriate data structure for the task. For example, if the candidate numbers are unique and sequential, you probably want an array of hashes:
my @candidates; # should use a hash instead, if my $c_id; # the numbering has lots of big gaps while (<>) { if ( /CANDIDATE\s+(\d+)/ ) { $c_id = $1; } elsif ( /DNA\s+.Note.\s*(\S*.*)/ ) { my $proteins = $1; my @p_set = (); while ( $proteins =~ /\[(NP\s+\d+)\]/g ) { push @p_set, $1; } $candidates[$c_id]{proteins} = [ @pset ]; } elsif ( /R-score\s*=\s*([.\d]+)/ ) { $candidates[$c_id]{rscore} = $1; } }
If you're still learning about data structures and references, I'm sure the relevant man pages will supply any other details you may need (perlreftut, perldsc). Use Data::Dumper as well, of course.

In reply to Re: regex with variable input by graff
in thread regex with variable input by BioGeek

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