in reply to Generalizing a REGEX

Your code doesn't compile, and it doesn't explain where $section comes from, which seems relevant since you intend for it to be the replacement portion of a substitution operator.

Here's an example of a substitution that does what you're asking for based on the example data you provided:

my @test_cases = ( ['cat.1', 'cat(1)'], ['', ''], ); foreach my $test (@test_cases) { my ($string, $want) = @$test; my $transformed = $string =~ s/\.(\d+)$/($1)/r; print "[$string] --> [$transformed] wanted: [$want]. Success: ", ( +$transformed eq $want ? "yes\n" : "no\n"); }

It's also an example of how to produce an SSCCE. Here's the output it produces:

[cat.1] --> [cat(1)] wanted: [cat(1)]. Success: yes [] --> [] wanted: []. Success: y +es