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"); }