in reply to How to deal with [ and ] chars

i would say to do a regex on $ptsp and insert backslashes before the square braces.
($ptsp = $ptlalsp[2]) =~ s/(\[|\])/\\$1/g;