对=~的疑惑

对=~的疑惑

我相匹配这样的一行,
D10(A),D9(B),D8(C),D7(D) 或者乱序  D7(D),D10(A),D9(B),D8(C)
请问我该怎么匹配阿,才能找出我想要的A B C D

我这样写了一perl但是不对,那位老师可以帮我之处错误
假设:
$in = D7(D),D10(A),D9(B),D8(C)
那么:
@tmp = (A,B,C,D);
foreach $tmp (@tmp){
    if($in =~ /$tmp\((.*)\)/){
         $want_1 = $1;
   }
}

我的$want_1总是得不到正确的内容,而是undef, 并且$in 的这会变
use warnings;
use strict;
my $in = "D7(D),D10(A),D9(B),D8(C)";
my @tmp = qw(A B C D);
foreach my $tmp (@tmp){
  if($in =~ /(\($tmp\))/) {
    my $want_1 = $1;
    print "$want_1\n";
  }else {
    print "no -matched\n";
  }
}
#!/usr/bin/perl -w

use warnings;
use strict;
my $in = "D7(D),D10(A),D9(B),D8(C)";
my @tmp = qw(A B C D);
foreach my $tmp (@tmp){
  if($in =~ /\(($tmp)\)/) {
    my $want_1 = $1;
    print "$want_1\n";
   
  }else {
    print "no -matched\n";
  }
}

这样才能得到想要的A,B,C,D吧。 楼上的得到的是(A),(B),(C),(D)。
但是=~到底是个怎么个用法呢?
Binary "=~" binds a scalar expression to a pattern match.  Certain operations search or modify the string $_ by
       default.  This operator makes that kind of operation work on some other string.  The right argument is a search
       pattern, substitution, or transliteration.  The left argument is what is supposed to be searched, substituted, or
       transliterated instead of the default $_.  When used in scalar context, the return value generally indicates the
       success of the operation.  Behavior in list context depends on the particular operator.  See "Regexp Quote-Like
       Operators" for details and perlretut for examples using these operators.