Hello, I want to replace text in file. So, I wrote subroutine like this: sub replace_txt { my ($old,$new) = @_; open (FILE,"<$ARGV[0]"); while(my $line = <FILE>) { $line =~ s/$old/$new/g; print $line; } close(FILE); }
when I use this subroutine line this: &replace_txt('$a', '$b'); but It doesn't work. $a in $ARGV[0] is still $a. But, when I rewrite my subroutine like this: sub replace_txt { open (FILE,"<$ARGV[0]"); while(my $line = <FILE>) { $line =~ s/\$a/\$b/g; print $line; } close(FILE); } It work fine. but I want to pass old and new text to subroutine as argument. How to do this? I search about this but I can't find any help so please help me.