It might be not the best way to do it, but for the regexp part I'd go with something like
use strict; use warnings; my $line = 'OPENINFO="Oracle_XA:Oracle_XA+Acc=P/NASIT/nasit+SesTm=60+S +qlNet=QANASIT+LogDir=/users/nas/disk1/data/traces+DB=QANASIT+Objects= +true+Threads=true"'; my $DBUser = '$DBUser'; my $DBPass = '$DBPass'; my $DBSid = '$DBSid'; my $openinfo_rx = qr/ \A OPENINFO=" # openinfo line start ( [^"]+ ) # whatever inside the '"'s " \z # openinfo line end /x; if ($line =~ m/$openinfo_rx/) { my $openinfo_content = $1; my $quoted_openinfo_content = quotemeta( $1 ); my (@openinfo_parts) = split( /$quoted_openinfo_content/, $line ); $openinfo_content =~ s{ =P/ # =P/ starts user/pass part ([^+]+) # whatever except + \+ # end mark for user/pass part } {=P/$DBUser/$DBPass+}x; $openinfo_content =~ s{ \+(SqlNet|DB)= # ([^+]+) # whatever except + \+ # end mark } {+$1=$DBSid+}xg; $line = join( $openinfo_content, @openinfo_parts); } print $line;
That assumes however that the strings used to anchor the parts that will be replaced won't never be also part of the text to be replaced - in your example, you migt have for example '+SqlNet=XXX+' instead of 'nasit' as password.
A supposition that might be true or not, so maybe the code would need to be tightened a bit if there are no known restrictions on the input data.

Hope that helps.

Krambambuli
---
enjoying Mark Jason Dominus' Higher-Order Perl

In reply to Re: Regular expression by Krambambuli
in thread Regular expression by Noame

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.