in reply to manipulation of ps command output

This is your problem line:
@PSarray = $PScmd ;
By that point, $PScmd already contains the result of the command. You are assigning all the lines to $PSarray[0].

There are two ways to fix your code, that I can see: