Sure,
To get it to the CGI you could add it to the URL:
location.href='script.cgi?Parameter='+myvar;
or by putting it in a hidden form field and submitting the form:
<script>
document.f.Parameter.value=myval;
</script>
<form name="f" action="script.cgi" method="post">
<input type="hidden" name="Parameter">
...
<input type="submit">
</form>
To get the variable back into JavaScript, have the CGI write the JavaScript. I use ASP, so I would use:
Response.Write "<script>var myvar=" & myvar & "';</script>"
In PHP it might be something like:
printf("<script>var myvar='%s'</script>",$myvar);