Counting Perfect Subsequences