If you search Github for "iphone sms" or "iphone messages", you can find lots of projects that will export your iPhone messages. So, if perl isn't your preferred language, there are plenty of other choices besides jwz's script.
Oh wow, awesome! Since python is my preferred language anyways I'll likely dig into this first.. since I'd be happy to toss you a pull request for sucking in images and video if feasible. Stoked to play with this later. Cheers.