my $highbitset= (1<< $firstbit); foreach ... ... $x & $highbitset) != 0);