in reply to substitution of a string with Square brackets.

use quotemeta to escape any special char in $2:
my $args = quotemeta $2; $line =~ s#$methodname\(($args)\)#private $methodname($1)#g;