my @SetBits= ( [], [0], [1], [0,1], [2], [0,2], [1,2], [3], [0,3] ... ... sub findsetbits { #feed with array of bytes my @result; my $offset=0; foreach my $byte (@_) { foreach (@{$SetBits[$byte]}) { push @result, $_+$offset; } $offset+= 8; } return @result; }