my %arg_xlate = ( func1 => sub { "proc1{$_[0]}" } , func2 => sub { "FUNC $_[0] END" } ); while () { my $line = $_; 0 while ($line =~ s/(func[12])\(([^()]*)\)/$arg_xlate{$1}($2)/ge); print $line; } __DATA__ func1(input1, func2(input2, input3)) func2(func1(input1, input2), input3)