It may be a bit late, but actually the script I posted a day before your post does something very similar to this…
http://forum.mikrotik.com/t/a-script-to-look-up-ip-to-rir-using-arin-whois/50820/1
If you want to trim the last character, then it is just a matter of doing something like:
:put [ :pick "test\n" 0 ( [ :len "test\n" ] -1 ) ];
As another example:
:local w "test\n";
:put [ :pick $w 0 ( [ :len $w ] -1 ) ];
To get characters up to the occurrence of the end of line (newline) character:
:local line "test\n";
:put [ :pick $line 0 [ :find $line "\n" ] ];
Regards.