Perl or SQL function to match dialplan pattern

Hey, sorry for the delay. The code worked after I modified it to read from database fields. Thanks!