Module app_perl allows execution of Perl scripts from SIP router configuration file, providing access to SIP message which is processed at that time. Exported functions by app_perl are available in the Perl script as package Kamailio.
References:
Perl API documentation is part of module README.