sub getforminput { my %in; my $buffer; # Because this is now a subroutine that can get # called from various places, we must be careful # not to tromp on the script's own variables. if ($ENV{'REQUEST_METHOD'} eq "GET") {$buffer = $ENV{'QUERY_STRING'};} elsif ($ENV{'REQUENT_METHOD'} eq "POST") { read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'}); } else { return undef; # If $ENV{REQUEST_METHOD} is not set, maybe there's no input. # In that case the script will probably print a blank form. } # I'm not sure what your assigning from $buffer to $bufferb was # intended to accomplish, but I think it just creates an extra # variable. Skip it, and go straight to the split: my @forminputs = split(/&/, $buffer); foreach $forminput (@forminputs) { my ($name, $value) = split(/=/, $forminput); $value =~ tr/+/ /; $value =~ s/%([a-fA-f0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # Some of that stuff cgi could do for you, possibly better, but # for now we'll move on... $in{$name} = $value; # Good. You did right to put the input in a hash. Not # only is it convenient to access that way, but it is # also all together in one nice container that can be # easily passed around, and there is no risk of tromping # on other variables (as there would be with $$name=$value # and similar hacks). } return \%in; }