You can anchor the regex to the end of the string with $. See perlrequick, perlretut, and perlre. Note the /r modifier I'm using is only available in Perl 5.14 (from 2011) and up.
$ perl -le 'print for map { s/\.(\d+)$/($1)/r } qw/cat.1 ld.so.conf.5 +/' cat(1) ld.so.conf(5)
Update: See also Re: How to ask better questions using Test::More and sample data
In reply to Re: Generalizing a REGEX
by haukex
in thread Generalizing a REGEX
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |