Outbound calling rules

Hi everyone,

I am new to Asterisk. I have a callback system working which calls back the caller after hanging up. I wanted to set up different calling rules for local calls and out of station calls. It seems my cli identifies local mobile calls with all the ten digits, out-of-station mobile calls with a 91 (ISD code for India, where I am based in) and fixed line calls as area code+phone#

[ul]My service provider has the following dialout rule.

For outgoing local mobile calls, I need to dial the full 10 digit mobile number as received, which is easy.
For outgoing out-of-station mobile calls, I need to dial “0+the ten digit mobile number” So I need to strip the 91 from the ${CALLERID(num)} and add a zero. This I can do with 0${CALLERID(num):2}

For incoming fixed-line calls I need to add a zero at the front which I can do as 0${CALLERID(num):0}
[/ul]
Is there any way to create a rule, such that the system identifies the incoming caller id and follows the corresponding rule? For instance if the incoming call is from a local mobile phone, it just calls back to the number as received. If it receives an out-of-station mobile phone call which would be a 12 digit number starting with 91, it strips 91 and adds a 9 to the front and if it is a fixed line number then it just adds a zero at the front of the number as received.