First, your question is not clear. Please rephrase it with respect to the code you are showing. I am guessing you mean that you want to make your own package which encapsulates (packages, hides) the mechanics of sending email, but what you have shown is just extracting various headers.
in reply to best way to transfor package Mail::Internet to Email::MIME and send mail
Second, your code would benefit from starting with:
#!/usr/bin/perl (or equivalent for your platform)