I can't see how to enter that with my $subst = <STDIN>;
True, it won't work this way ... it might be feasible with a slight syntax tweak and one further step to process it ... assumes that you know ... you might need some newline characters to be reprocessed

As long as you can get  \nything into a scalar, you can search/replace with it, and a statement like
    my $subst = <STDIN>;
is perfectly adequate to capture any sequence with a literal backslash in it:

c:\@Work\Perl>perl -wMstrict -e "print 'enter a string: '; my $string = <STDIN>; chomp $string; print qq{'$string' \n}; " enter a string: )\n( ')\n('
(Caveat: Actually, I can only test this under Windoze; there may be OSen that mung backslashes in situations like this.)

Once you have captured a string with a backslash, you can use it for search/replace straightforwardly:

c:\@Work\Perl>perl -wMstrict -le "printf 'enter search regex: '; my $search = <STDIN>; chomp $search; ;; printf 'enter replacement string: '; my $replace = <STDIN>; chomp $replace; ;; print qq{doing s/$search/$replace/}; ;; my $s = qq{as\ngh\njk}; printf qq{%*s: '$s' \n}, 7, 'initial'; ;; my @regex = ( { lh => $search, rh => $replace, }, ); ;; for my $hr_s (@regex) { $s =~ s[ (?-x)$hr_s->{lh}]{ qq{qq{$hr_s->{rh}}} }xmsgee; } ;; printf qq{%*s: '$s' \n}, 7, 'final'; " enter search regex: \n enter replacement string: __\n__ doing s/\n/__\n__/ initial: 'as gh jk' final: 'as__ __gh__ __jk'
(This is essentially the example code from below.)


Give a man a fish:  <%-{-{-{-<


In reply to Re^4: Regex stored in a scalar by AnomalousMonk
in thread Regex stored in a scalar by OtakuGenX

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.