use strict; use warnings; use String::Substitution qw(gsub_copy); my $in_string = 'foo.ra'; my $find_exp = '\.(.)(.)$'; my $replace_exp = 'b$2$1s'; my $output = gsub_copy($in_string, $find_exp, $replace_exp); print "$output\n"; # prints: foobars