i need help with this regex to capture only the exact match within a string and put it in a variable
i only want to extrapolate these values (fixed list; no other numbers):
004010H222A1 or
004010H223A2 or
004010H220A1 or
004010H279A1 or
004010H279A1 or
004010H217
from the string given
example:
$str = "this is the code 004010H222A1 the rest is irrelevant";
$str = "the random number is 004010H223A2 ** anything else is irrelevant";
$str = "the last lottery number 004010H220A1 ~~ the rest is irrelevant";
$str = "yet another random sentence 004010H279A1 the rest is irrelevant";
$str = "any sentence before what i want 004010H279A1 the rest is irrelevant";
$str = "last winning number 004010H217~~~";
if ($str =~ /\b(004010H[2][1|2|7][0|2|3|7|9])(A[1|2])?\b/){
print "found exact match\n";
##put result into a variable
##example:
## $exact_match = <found eg 004010H222A1>;
##print $exact_match;
}
how can i capture the exact match of what i want into a variable then display it? maybe i just can't see the forest for the trees. thank you in advance for your help