You don't need $query around $nick for it to work. It was just the ^ causing the problem.