Well, I really recommend using CGI.pm, as everyone else has suggested, but I believe the problem with the code is:
if(ref($INPUT{$thing}) eq "ARRAY") { $INPUT{$thing} = join('^', $$INPUT{$thing}); }
Specifically:
join('^', $$INPUT{$thing})
You've already determined that $INPUT{$thing} is an array reference, so the proper way to de-reference it is:
@$INPUT{$thing}
Or (more clearly)
@{ $INPUT{$thing} }
So your final solution is:
if(ref($INPUT{$thing}) eq "ARRAY") { $INPUT{$thing} = join('^', @{$INPUT{$thing}}); }