I don't understand the question, I'm blinded by the long lines and can' find the problems.

You can use just about any characters as delimiters in s///, you don't have to use the slash. By using something else, say matching curly braxes, you don't have to excape all those slashes that are part of the text. And you don't have to searcxh character by character to find the separation between 'search' and 'replace'.

As well, if you want to specify 5 spaces, you can use \s{5} rather than \s\s\s\s\s. It means you don't have to count; you KNOW the pattern is looking for 5 of them. Ooops, there's actually 6 of them....proves my point. It doesn't matter that braces are nested, cause braces are balanced.

# Up in the Constants section # Readonly my $NL = "\n"; Readonly my $RETURN = "\r"; Readonly my $SPACE = q{ }; Readonly my $TAB = "\t" my $search_text = qr{<binddn>cn=abcde</binddn> # buttondown $NL # newline $SPACE{6} # 6 spaces <bindpass> # something .* # anything </bindpass> # end something }xms; my $replace_text = "<binddn>cn=abcde</binddn>$RETURN$TAB<bindpass>welc +ome1</bindpass>"; $line =~ s{$search_text} {$replace_text};

As Occam said: Entia non sunt multiplicanda praeter necessitatem.


In reply to Re: String replace, another question by TomDLux
in thread String replace, another question by heeru

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.