Uncaught TypeError: preg_match(): Argument #2 ($subject) must be of type string, array given

Hello everyone I need a small help with PHP compatibility with PHP 8.x.

The problem is that with PHP 7.4 everything works fine, but when I upgrade to PHP 8.0 or 8.1 with one specific feature when I do an action I get an error: “There has been a critical error on your website”. The interesting thing is even if I get this error function does its job even after this error.

I have enabled debugging and traced to PHP code:

            // Check with custom fields start
            if ($to_chek_cust_withval != '') {
                $cand_edu_titles_list = get_post_meta($cand_id, 'jobsearch_field_education_title', true);
                $cand_exprience_titles_list = get_post_meta($cand_id, 'jobsearch_field_experience_title', true);
                if (!empty($cand_edu_titles_list)) {
                    foreach ($cand_edu_titles_list as $cand_edu_title) {
                        if ($cand_edu_title != '' && $to_chek_cust_withval != '' && @preg_match("/{$cand_edu_title}/i", $to_chek_cust_withval)) {
                            $validation_arr['custom_field'] = '1';
                            break;
                        }
                    }
                }
                if (!empty($cand_exprience_titles_list)) {
                    foreach ($cand_exprience_titles_list as $cand_exprience_title) {
                        if ($cand_exprience_title != '' && $to_chek_cust_withval != '' && @preg_match("/{$cand_exprience_title}/i", $to_chek_cust_withval)) {
                            $validation_arr['custom_field'] = '1';
                            break;
                        }
                    }
                }
            }
            // Check with custom fields end

And the “main error line – main thrown in” is shown that this is the problem:

 if ($cand_edu_title != '' && $to_chek_cust_withval != '' && @preg_match("/{$cand_edu_title}/i", $to_chek_cust_withval)) {

Can someone help me out with this and give me a fixed PHP line? Please. Thank you.

Tried to search for deprecated functions, Preg in PHP, and more. The syntax is looking good. Could you please check and give a fixed code line?