Most definitely this is str_replace issue, in fact a bug in str_replace builtin function. Here is a trivial interactive example.
pubs2:1> declare @proctext varchar(100)
pubs2:2> select @proctext = "create procedure p_test as select * from publishers"
pubs2:3> select @proctext = str_replace(@proctext, "p_test", "p_test_v22")
pubs2:4> select @proctext
pubs2:5> go
(1 row affected)
(1 row affected)
----------------------------------------------------------------------------------------------------
create procedurep_test_v22t as select * from publishers
(1 row affected)
pubs2:1>