You probably want to say something like this: if( grep { $number4 == $_ } 1, 2 ) {...