in reply to substitution of a string with Square brackets.
Use \Q and \E to quote the string:
$line =~ s#$methodname\((\Q$2\E)\)#private $methodname($2)#g [download]