Unless you can guarantee that
1) SAM is always going to be 3 characters
2) there will only be 1 character between SAM and TEST
3) 1.2.3.4 will always be 7 characters
4) there will always be 1 character at the end
then I would not recommend even trying to use $left, $mid, $right
A much more flexible set of options exists using token identifiers
;set variable abc to sam[test@1.2.3.4]
%abc = sam[test@1.2.3.4]
;set %nick to match the characters starting from the beginning of the variable %abc to the first occurance of ascii character 91 (aka [)
%nick = $gettok(%abc,1,91)
;set %ident to match the characters starting from the beginning of the variable %abc to the first occurance of ascii character 64 (aka @)
%ident = $gettok(%abc,1,64)
;set %ident to match the characters going from the end of %ident to the first occurance of ascii character 91
%ident = $gettok(%ident,-1,91)
;set %host to match the characters going from the end of %abc to the first occurance of ascii character 64
%host = $gettok(%abc,-1,64)
;set %host to match the characters going from the beginning of %host to the first occurance of ascii character 93 (aka ])
%host = $gettok(%host,1,93)
I have included detailed explanations as to how each step in the code would proceed, due to the fact that you have been referred to token identifiers previously and are still trying to get the information the hard way.
To summarize the above code
%abc = sam[test@1.2.3.4]
%nick = $gettok(%abc,1,91)
%ident = $gettok($gettok(%abc,1,64),-1,91)
%host = $gettok($gettok(%abc,-1,64),1,93)