printf "ans = %d\n", scalar m|\b$KEY\b|g;
でもよさそうな?