A more general application of your second technique was posted by
Abigail-II in
Re: Stepping through an array - This thread also includes a benchmark between these
grep and slice techniques.
perl -le 'print+unpack("N",pack("B32","00000000000000000000001000011111"))'