I have this nagging, uncomfortable sense that I've not understood your question... but does this (simplified and not cargo-cult-able) code do what you intend?

#!/usr/bin/perl use strict; use warnings; use 5.016; my @lines = ("RECORDNAME foo bar baz RECORDIP 127.2.2.1 \n", "RECORDNA +ME 1 2 3 4 5 RECORDIP 127.1.1.1\n", "RECORDNAME abcd e fgh ij RECORDI +P 127.0.0.1\n"); my $fqdn = qq/www.test.sample/; my $address = qq/nowhere_ville/; say @lines; say "-" x10 . "\n"; my @newlines = ''; for $_(@lines) { $_ =~ s/RECORDNAME/$fqdn/; #no need to /ee if your vars are sca +lars $_ =~ s/RECORDIP/$address/; push(@newlines, $_); } say @newlines;
OUTPUT:
> perl 1081659.pl RECORDNAME foo bar baz RECORDIP 127.2.2.1 RECORDNAME 1 2 3 4 5 RECORDIP 127.1.1.1 RECORDNAME abcd e fgh ij RECORDIP 127.0.0.1 ---------- www.test.sample foo bar baz nowhere_ville 127.2.2.1 www.test.sample 1 2 3 4 5 nowhere_ville 127.1.1.1 www.test.sample abcd e fgh ij nowhere_ville 127.0.0.1

If not, try re-reading your node and clarify (if you can infer it) whatever confused me. And read about quotelike operators ( perlop - scroll down to "Regexp Quote-Like Operators" and "Quote-Like Operators" ) for possibly useful information.


Questions containing the words "doesn't work" (or their moral equivalent) will usually get a downvote from me unless accompanied by:
  1. code
  2. verbatim error and/or warning messages
  3. a coherent explanation of what "doesn't work actually means.

In reply to Re: search and replace with a variable by ww
in thread search and replace with a variable by tronmason

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.