use CGI; my $cgi = CGI->new; for ($ENV{QUERY_STRING}) { delete $cgi->{param}{keywords} if length && !/[&=]/; } ... rest of the code goes here ...