in reply to Undefined subroutine

The problem is that send_email is not exported to the namespace of your calling script, so the subroutine is undefined. Two solutions: Use the fully-qualified name to call the sub, e.g. EmailSender::send_email( $username, $body ); or use Exporter to export the symbol to the calling namespace:
package EmailSender; use base 'Exporter'; our @EXPORT_OK = ( 'send_email' ); ... 1;
And then in your calling script:
use EmailSender 'send_email';