my @array = (10,11,12,13,14,20,21,25); my $x = 1; my %array = map { $_ => undef } @array; if( exists $array{$x} ){ ... }