I hope I did understand your problem. Here is my sample code. Kindly check it if the flow and output fits to the solution of your problem. If it didn't, I hope it can give you some clues. Just like Javafan said check each word of "my_name" if they all exist in one of the string of database "db_name".

#!/usr/bin/perl -w @my_name=("Acidovorax","JS42"); #name to be searched... #...split by term/words @db_name=("Acidovorax sp. JS42", #data base of names in array "JS42 Acidovorax sp.", "JS42 sp. Acidovorax", "JS53 sp. Acidovorax", "JS42 sp. Axidovorax", "JS42Acidovorax sp. " ); my $ctr; #----compare strings in $db_name 1 at a time foreach my $db_each (@db_name){ #----search each term/word of @my_name in $db_each foreach($ctr=0; $ctr<=$#my_name; $ctr++) { #----if a term/word not found break the loop last if($db_each !~ /\b$my_name[$ctr]\b/i); } #----this will be true if inner foreach didn't break if($ctr==$#my_name+1) { print "$db_each\n"; #print the matched name } } <>;

I have mention the "term/word" in the comment. It might be that two words in your "my_name" is considered as one term or two or more words separated by space.

The code above does not support if a word should exist 2 or more times in any order. example: my_name = "high class bacteria f7-52 high fever". Just mentioning this condition for more flexibility to your program. It's still up to you.


In reply to Re^3: Reg exps? by toastbread
in thread Reg exps? 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.