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: <%-{-{-{-<
|