in reply to Find Replace into a subroutine

Here how it is: ...........

....... and it is wrong from the beginning:

chomp(my $rc_1 = '$rc_file1');

Read chomp to learn what it does. The above line just stuffs the literal $rc_file1 into the variable $rc_1; chomp does nothing here. As it doesn't anywhere else in your code. Read up on chop, also.

Your code is written in a way it is nearly impossible to read and get what it is intended for; variables with unknown content appear out of the blue; cloning of variables is done without ever using the resulting variable (e.g. $rc_1); the formatting is poor.

So, before even thinking in refactoring, clean up that mess first.