This looks like the 'nicest' (from a code readability and compactness point of view) solution to me, shame that it's not standard Perl but instead requires an extra module.
So I have chosen to use if ($n==40 || $n==47 || $n==76) {
which works fine too (regardless whether I use 'or' or '||').