http://qs321.pair.com?node_id=11120504


in reply to Generalizing a REGEX

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