Not sure if I'm understanding the idea, but this seems more a question about sql queries or about sending/receiving plain text sms, so I wonder how are you adding perl to this equation. Maybe putting all the needed info in a stream and chunk the stream?. Can we see some code?