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.
Second, your code would benefit from starting with:
#!/usr/bin/perl (or equivalent for your platform) use strict; use warnings;