Firefox is extended with Javascript and XUL (an XML widget declaration language). If you'd STFW you can very easily find things such as this tutorial at developer.mozilla.org.
As for using Perl, I'm pretty sure you can't directly; I'm also marginally sure that you can't directly call out to an external binary (analogous to opening a pipe or calling system) even from Javascript in an extension. You could however probably interact with Perl running on a remote webserver, but I don't think that's what you're asking for.