Multiple freepbx site, short internal number


I my company we are currently moving our phone system to a freepbx voip system :wink:

the first step was to install one freepbx server (that i will name PBX_A) with a SIP trunk to one provider with 2 IP phones and some softphones
this was done without any issue :wink:

The assigned internal phone numbers are short two digit

we will install a freepbx server (PBX_B) on another location with its own SIP trunk (that is not an issue as it is the same as our first freepbx :wink: )

now the fun part :
we need to make both freepbx server communicate with each other
both location needs to have short internal numbers :wink:

but both location should be able to reach people without using the SIP trunk

for example the person with PBX_A number 10 wish to reach the person with PBX_B number 11

we defined a quick convention : number starting with 9 are for internal multisite call
then comes a 2 digit location code, then the internal number

so PBX_A has location code 01
and PBX_B has location code 02

so the person at PBX_A with internal number 10 should dial
90211 to reach person a PBX_B with internal number 11

one extra difficulty would be that long number should also work
for example if PBX_A user 10 by mistake typed 90111 it still would call the direct number 11

can someone guide me how to do this ?

Thank in advance