if ($arr =~ /(\w*)(abc)(\d{5})/){ $a = $3 if (($arr =~ / (\w*)(def)(\d{8})/){ $b = $3 } } print $a; prnit $b;