my %hash; @hash{0, 15, 16, 31} = (); # then add this to your benchmark hash => sub { while ( $data =~ /^(\d+) (\d+)/mg ) { next if exists $hash{$1} or exists $hash{$2}; return 1; } },