print $file $_ if s/$LeftSide/$RightSide/eegi; #### print $_ if s/$LeftSide/eval $RightSide/egi; #### # main.pl # all this is just a template that creates "run.pl" use strict; use warnings; while(){ print $_ if s/search_here/replace_here/gi; } __DATA__ (123),(456),(789) (abc),(def),(ghi) #### # prepare_run.pl open my $file, '+<', 'main.pl'; #your original script we will replace keywords open my $run, '+>', 'run.pl'; #newly created script that we will execute below print "Enter left side of s///: "; chomp(my $LeftSide = ); print "Enter right side of s///: "; chomp(my $RightSide = ); while(my $line = <$file>){ print $run $line if $line !~ /.*search_here.*/ || /.*replace_here.*/; print $run $line if $line =~ s/(.*)search_here(.*)/$1$LeftSide$2/ && $line =~ s/(.*)replace_here(.*)/$1$RightSide$2/; } close($file); close($run); system("run.pl"); #or whatever the the equivalent of your OS. #### # run.pl, will be created after running "prepare_run.pl" while using "main.pl" as a template. use strict; use warnings; while(){ print $_ if s/\),\(/\)\n\(/gi; } __DATA__ (123),(456),(789) (abc),(def),(ghi) #### (123) (456) (789) (abc) (def) (ghi)