... ### MAIN # we get a reference to body my $unencrypted_body = &parse_email($stdin); # ***NEW*** sent dereferenced body by mail mail_it( $$unencrypted_body ); ... sub decode { my $entity = shift @_; #Create new Mail GPG obj my $mg = Mail::GPG->new; #Decrypt the email from stdin my ($decrypted_entity, $result) = $mg->decrypt ( entity => $entity, passphrase => $passphrase ); #Get a reference to the decoded message body my $decoded_body_sref = $result->get_gpg_stdout; return $decoded_body_sref; # ***NEW*** removed mail sending } # ***NEW*** own subroutine for mail sending sub mail_it { my $mailtext = shift; my $to = 'chris'; my $from = 'root'; my $subject = 'Test Email'; open( my $mailer, "|-", "/usr/sbin/sendmail -t" ) or die "Could not open sendmail: $!"; # one print to print it all print $mailer <<"END_OF_MESSAGE"; To: $to From: $from Subject: $subject $mailtext END_OF_MESSAGE close( $mailer ) or die "Close sendmail failed: $!"; print "Email Sent Successfully\n"; }