import re

string = """
BeginA
Qwerty
Element 11 35
EndA

BeginB
Element 12 38
...
Element 198 38
EndB

BeginA
Element 81132 38
SomethingElse
EndA

BeginB
Element 12 39
Element 198 38
EndB"""


block = re.compile(r'BeginB[\s\S]+?EndB')
element = re.compile(r'Element.*?\b38\b')

def repl(match):
	return element.sub('Element ABC', match.group(0))

nstring = block.sub(repl, string)
print(nstring)