in reply to Regex stored in a scalar

You can execute your substitution on the default string $_.
use strict; use warnings; my $string = '(abc),(def),(ghi)'; my $substitution = 's/\),\(/\)\n\(/gi'; $_ = $string; eval "$substitution"; print;

OUTPUT:

(abc) (def) (ghi)
Bill

Replies are listed 'Best First'.
Re^2: Regex stored in a scalar
by BillKSmith (Monsignor) on Aug 22, 2015 at 18:53 UTC
    Since my original reply, I have discovered that my concept of "build the command and evaluate it" can be generalized to meet your original requirement.
    use strict; use warnings; my $regex=<STDIN>; #Entering s/\),\(/\)\n\(/gi chomp $regex; open (INPUTFILE, "< $filein"); while (<INPUTFILE>) { my $line=$_; #$line =~ $regex; eval "\$line =~ $regex"; };
    Bill