in reply to Re^2: Reg exps?
in thread Reg exps?

This is more or less redundant after toastbread's response and quite possibly naive but I've done it now and it seems to do what the OP wanted:
use strict; use warnings; my $my_name="Acidovorax JS42"; my $db_name="Acidovorax sp. JS42"; my @names = split " ", $my_name; my $numel = @names; #number of words to match my $count; foreach (@names) { if ($db_name=~/^|\s\Q$_\E$|\s/) { $count++; #count matches } } print "MATCH" if $count==$numel; #report match if all words match
--->Updated to fix regex - thx JavaFan

Replies are listed 'Best First'.
Re^4: Reg exps?
by JavaFan (Canon) on Jan 14, 2010 at 19:06 UTC
    You would have to escape $_ as it may contain regexp special characters. It also assumes "words" are delimited by whitespace and by \b at the same time - your program fails to find a match if $my_name=$db_name="Acidovorax sp. JS42" for instance.
      Ouch! I guess I should learn to program before I start (mis)representing myself as someone who knows what he's talking about. I've updated the post with what I think might possibly work. Thanks for the heads up.