Implement 'tr' function