Just a slight correction, $mid($2,@) should be $mid($2,2), I probably held shift while typing "2". I don't think this typo affects the script though.