use constant SEARCH => 0; use constant REPLACE => 1; my %translate = ( funca => [ qr/funca\( ([^,]+) , ([^,]+) ,([^,]+) ,([^)]+) \)/x, '"func($1,$2,XXX,YYY,$4)"' ], funcb => [ qr/funcb\( ([^,]+) , ([^,]+) ,([^,]+) ,([^)]+) \)/x, '"func($1,$2,,,$4)"' ], ); while () { for my $key (keys %translate) { if (/$key/) { s/$translate{$key}->[SEARCH]/$translate{$key}->[REPLACE]/ee; print; } } } __DATA__ funca(10,20,30,40) funcb(10,20,30,40)