()は一つ減らせる
my ($a1) = $a =~ /(\d+)/g;
これでもいける
my ($a1) = $a =~ /\d+/g;