#!/usr/bin/perl
use feature "say";
use strict;
use warnings;

my $content = "I am trying to capture this 1910.1024,  this 1910.1024(a) and  this 1910.1024(a)(3).";
if($content =~ m/([0-9]{4})\.([0-9]{4})/) {
   $content =~ s{
   	    ([0-9]{4})      # $1 = First 4 digits
   	    \.              # Dot
   	    ([0-9]{4})      # $2 = Second 4 digits
   	    (?:\((\w+)\))?  # (, $3 (first optional "word"), )
   	    (?:\((\w+)\))?  # (, $4 (second optional "word"), )
    }{
   		"<!!uf dp_ecfr29 29cfr$1x$2 #29cfr$1x$2" .
		(defined($3) ? "z-$3" : "") . (defined($4) ? "-$4" : "") .
		">$1.$2" . 
		(defined($3) ? "($3)" : "") . (defined($4) ? "($4)" : "") . 
		"</a>"
    }gxe;
	say "$content\n";
} else {
   say "Error";
}

