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

In reply to Re: Passing $1 as part of a variable value to a regex search and replace by Marshall
in thread Passing $1 as part of a variable value to a regex search and replace by zow

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.