Of course the %a is going to be the same before and after the code has run, since you aren't altering %a. The code says to search for the channel followed by any number of characters (btw, I noticed that I accidentally used %chan not $chan for the search parameter), then if the channel is found in %a concatenate the channel name with the | character and the current time, then place that information into the variable %userchans.
Thus %userchans would contain the altered information, not %a
Also note that %a and %userchans will change for each run of the code, and if the channel name isn't found in %a then %userchans will get set to $null