in reply to Passing $1 as part of a variable value to a regex search and replace

I don't see the need to mess around with this $1 variable.
I would use list slice to eliminate that. This is a powerful technique.

Maybe I'm not getting the gist of the requirement, but it appears that you want the alpha stuff before the numbers start in two vars and want to modify a var based upon that. I think the code below could be generalized into a looping construct.

#!/usr/bin/perl -w use strict; #this gets chars until first digit... my $search = "some_string200912.txt"; my $alpha1 = ($search =~ m/(.*?)\d+.txt/)[0]; #this gets chars until first digit... my $to_modify = "some_value200912.txt"; my $alpha2 = ($to_modify =~ m/(.*?)\d+.txt/)[0]; #this modifies (assigns new value to $to_modify) $to_modify = "$alpha2"."_"."$alpha1"; print "$to_modify\n"; __END__ prints: some_value_some_string
Update:

if the list slice on the right hand side offends you, put the left hand side into list context like this:

#!/usr/bin/perl -w use strict; #this gets chars until first digit... my $search = "some_string200912.txt"; (my $alpha1) = $search =~ m/(.*?)\d+.txt/; #this gets chars until first digit... my $to_modify = "some_value200912.txt"; (my $alpha2) = $to_modify =~ m/(.*?)\d+.txt/; #this modifies (assigns new value to $to_modify) $to_modify = "$alpha2"."_"."$alpha1"; print "$to_modify\n"; __END__ prints: some_value_some_string