quote and quote_identifier are both database handle methods. Which means that you'd have to load DBI (and the appropriate DBD) to get the database handle to call these methods. So, going this route, the OP might as well refactor to just use DBI instead of the shell. Or, if for some reason, he can't use or install DBI, then at least untaint the data and escape the characters that you're willing to accept that need escaping.