JS is a browserside language. It runs in the browser only.
Perl is a server side lanaugage and runs only on the server.
JS can set and read cookies. The only time those cookies are sent to the server is via a request as part of the HTTP header. Most often, that request is going to be a result of a pageview or downloading a graphic.
Somehow we have to get that cookie back to the perl program to work on. Most times, that is going to be directly calling that Perl program. Then the perl program can look at the server headers where the cookie data resides, and then do something with it.
So, the challenge is getting it into Perl - 3 options to pass the data to Perl via a HTTP header:
a page view. You directly call the perl script.
AJAX. quietly call your perl script from AJAX formated code to send the cookie.
a transparent image graphic pull that actually calls the perl script.
How you go about each of those is a bit different.
I would say you first homework, is to study perl enough to figure out how to get the cookie from the http headers. Then move on to figuring out how you are going to get the cookie from the browser.