Trace Local and Outside Calls

Guys,

Is there a way to isolate outside call over local / extension calls?

here’s the scenario.
if a call is from outside and the caller dialed 300 it should go to 301.
if a call is from extension or local and a caller dialed 300 it should go to 300.

the idea is to route the call to the secretary if a call is from outside.

do you have idea if it is possible?