Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Regexp substitution using variables

by Bod (Parson)
on Nov 25, 2020 at 19:53 UTC ( [id://11124221]=note: print w/replies, xml ) Need Help??


in reply to Regexp substitution using variables

You need to add the modifiers at the start of the substitution like this:

use strict; my $pattern = 'test'; my $replacement = 'New'; my $flags = 'i'; my $value = 'My Test Text'; $value =~ s/(?$flags)$pattern/$replacement/; print "$value\n";
This will print:
My New Test

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11124221]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (1)
As of 2024-04-25 01:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found