in reply to Taking arbitrary elements from an array

Yeah, I'd go with the unpack and a slice.

my @arr = qw( and you will be pleased with the results ); my $mask = 0x2b; sub mask_array (\@$) { my( $arr, $mask ) = @_; my @want = split '', unpack( "b*", $mask ); return @{ $arr }[ grep { $want[ $_ ] } 0..$#{ $arr } ]; } my @result = mask_array @arr => $mask;

Update: Hypothetically you could use return @{ $arr }[ grep { vec( $mask, $_, 1 ) } 0..$#{ $arr } ] instead of making @want, but I'd bet that's a little slower than the above version.