can we replace selected segment with the desired another segment, any script please help

can we replace selected segment with the desired another segment, any script please help