You probably want to say something like this: if( grep { $number4 == $_ } 1, 2 ) {... #### use List::Util 'any'; # ......... if( any { $number4 == $_ } 1, 2 ) {... #### Or more simply... if( $number4 == 1 || $number4 == 2 ) { ...