$a =~ /(\d+)/;
$a1 = $1;

を1行かけませんか?