my @test_cases = ( ['cat.1', 'cat(1)'], ['ld.so.conf.5', 'ld.so.conf(5)'], ); 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"); } #### [cat.1] --> [cat(1)] wanted: [cat(1)]. Success: yes [ld.so.conf.5] --> [ld.so.conf(5)] wanted: [ld.so.conf(5)]. Success: yes