$line =~ /$regex/;
is a substitution operator, it is not a regex. Only the part between the first two slashes is a regex, not the rest.s/\),\(/\)\n\(/
So if you want to make substitutions you probably want to capture two inputs from the user or from the command line, the searched pattern and the substitution (not tested).
And for a big file, you might want to add the o modifier, it may be faster (but that may depend on your version of Perl).my $regex = <STDIN>; chomp $regex; my $subst = <STDIN>; chomp $subst; while (<INPUTFILE>) { my $line = $_; s/$regex/$subst/gi; }
Update: Oh, BTW, if you're used to do it in vi, you might consider sed. You should feel at home.
Update 2: I crossed out the first part of my answer, as it was at least very incomplete, as kindly pointed out by AnomalousMonk. Only the second part was really relevant to the OP problem.
In reply to Re: Regex stored in a scalar
by Laurent_R
in thread Regex stored in a scalar
by OtakuGenX
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |