but its not working as expected
Really? It's working exactly how I'd expect it to (i.e. not at all). If it's not working how you'd expect it to, then change your expectations.
Go back to square one. Learn how the Web works. In particular pay attention to the distinction between client-side and server-side scripting.
Think of it this way. My name is Mr Server; your name is My Browser. We live in different towns. We can talk on the telephone, but if I'm eating a bacon sandwich while we're talking, you can't smell it.
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'