Another solution might just to generate the regular expression based on the user input. Assuming simple command-line script (or something similar, I didn't see the source of 'users query'. Easily ported to a web-app or something along those lines). You could do something along the lines of:
#!/usr/bin/perl use strict; use warnings; my $regex_cache = {}; die "Usage $0 [CAC <NUM> TTT <NUM>]\n" if ( @ARGV % 2 ); my %input = @ARGV; # Where the input would be : CAC 2 TTT 2 my $data_set = <DATA>; for my $in ( keys %input ) { my $reg_key = "($in)\{$input{$in}\}"; my $reg = $regex_cache->{$in} ||= qr/($reg_key)/s; print "$1\n" if ( $data_set =~ $reg ); } __DATA__ ATCACCACTTCCTGGACACTACCCTAAACCTTTGAGGA AATAACCGCTTTGTTGTTGCGATCGCCTAATAAATATC AGCGTCTTCGTATGATAAACCAATGCGGAAGTACAAAA
Now, much like the other comments in this thread, I'm not really sure what type of order you are looking for in the set. If 2 CAC means 'CACCAC' or 'CAC\w*CAC', etc. Given the fact that I may have missed this, the compilation of the $reg_key can be changed to be something else. Nevertheless, it will still be able to parse the file based of some sort of input, which is what I believe you were generally looking for.

Sorry if I'm way off base here and my input doesn't help, although I certainly hope it does. Good luck!

---hA||ta----
print$_ for(map{chr($_)}split(/\s+/,join(/\B?:\w+[^\s+]/,<DATA>))); __DATA__ 67 111 100 101 32 80 101 114 108

In reply to Re: generate regular expression by wazzuteke
in thread generate regular expression by khoueiry

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.