It's not nearly that complicated.

/help $comchan

since raw 318 is ENDOFWHOIS, I think this should work.

Code:

raw 318:*: {
  var %pmnic = $2, %a = 1, %b = $comchan($2,0), %chans
  while ( %a <= %b ) {
    %chans = %chans $comchan(%pmnic,%a)
    inc %a
  }
  if (!%chans) echo -ca whois No Common Channels
  else echo -ca whois Common Channels with %pmnic are %chans
}



These are all local variables, so they will 'disappear' once the result is echoed.

I'm not really sure that the var %pmnic needs to be set at all, but thought it might prevent problems if several whois calls should be generated very quickly.

This should probably be adjusted if you are on multiple servers.
I don't do multiple servers, so I haven't bothered to learn.

/help multi-server

Hope this helps