$SET_FIELD="first_child|next_sibling|pcdata|cdata|ent|data|target|comment|flushed"; s{(\$[a-z_]+(?:\[\d\])?) # $1: the object ->set_($SET_FIELD) # $2: the field to set \(([^)]*)\)} # $3: the value (must not include ()) {$1\->\{$2\}= $3}gx;