That script doesn't produce the error you describe. It generates:
Global symbol "$trans_type" requires explicit package name at noname.p
+l line 26.
Global symbol "$transaction_id" requires explicit package name at nona
+me.pl line 28.
Global symbol "$mem_number" requires explicit package name at noname.p
+l line 29.
Global symbol "$apt" requires explicit package name at noname.pl line
+30.
Global symbol "$month" requires explicit package name at noname.pl lin
+e 31.
Global symbol "$year" requires explicit package name at noname.pl line
+ 32.
Global symbol "$amount" requires explicit package name at noname.pl li
+ne 33.
Global symbol "$gateway" requires explicit package name at noname.pl l
+ine 38.
Unmatched right curly bracket at noname.pl line 42, at end of line
syntax error at noname.pl line 42, near "}"
noname.pl has too many errors.
Maybe you should run the sample code you post before you post it to check that it demonstrates the problem you describe?
Note that Perl gives you better ways to generate blocks of inline text:
use strict;
use DBI;
use CGI::Session;
use CGI qw(:standard);
my $query = new CGI;
print <<HEADER;
HTTP/1.0 200 OK\n";
Content-type:text/html
<HTML>
<Head>
<Title>Members</Title>
</Head>
<body>
HEADER
my $sid = $query->cookie("CGISESSID") || undef;
my $session = new CGI::Session(undef, $sid, {Directory => 'Temp/'});
my $trans_type = 'xxx';
my $transaction_id = 'xxx';
my $mem_number = 'xxx';
my $apt = 'xxx';
my $month = 'xxx';
my $year = 'xxx';
my $amount = 'xxx';
my $naijaXMLRequest = <<XML;
<Lastbill>";
<TransactionType>$trans_type</TransactionType>";
<MerchantID>NAIJAMAN009</MerchantID>";
<TransactionID>$transaction_id</TransactionID>";
<MemberNum>$mem_number</MemberNum>";
<apt>$apt</apt>";
<aptExpMonth>$month</aptExpMonth>";
<aptExpYear>$year</aptExpYear>";
<TotalAmountdue>$amount</TotalAmountdue>";
</Lastbill>";
XML
my $mem = new LastBill;
my $gateway = 'xxx';
$mem->sendHTTP($gateway, "$naijaXMLRequest");
$session->delete();
print
qq[<script type='text/javascript'>window.open('','_self','');windo
+w.close()</script>];
and that CGI will generate the header for you using print $cgi->header();.
Showing us the CGI related code probably isn't relevant to your issue so you could remove that to focus on the real problem you want help with.
Premature optimization is the root of all job security