my $cn = qr/chapnum/; my $cp = qr/chapter/; $str1 =~ s#(1\s*\s*)(<$cp>\s*<$cn>1A)#$1$2#s;