s/^ \s* my \s* \(?\s* \$page # page is the variable \s*\)? \s* = \s* \&? # function may or may not be explicitly contexted create_page # function name \s* \(\s* # Begin param ([^,]+?), # 1st param \s* ([^,]+?), # 2nd param \s* ([^,]+?), # 3th param \s* ([^,]+?) # 4th param \s*\) # End param ; /your_replace_string/x;