diff --git a/tools/perf/tests/shell/record+probe_libc_inet_pton.sh b/tools/perf/tests/shell/record+probe_libc_inet_pton.sh
index 0f01c62cbee9..5b424be76716 100755
--- a/tools/perf/tests/shell/record+probe_libc_inet_pton.sh
+++ b/tools/perf/tests/shell/record+probe_libc_inet_pton.sh
@@ -30,28 +30,36 @@ add_libc_inet_pton_event() {
 
 trace_libc_inet_pton_backtrace() {
 
-	expected=`mktemp -u /tmp/expected.XXX`
+	declare -a expected
+	local -i idx=0 hit maxstack=4
 
-	echo "ping[][0-9 \.:]+$event_name: \([[:xdigit:]]+\)" > $expected
-	echo ".*inet_pton\+0x[[:xdigit:]]+[[:space:]]\($libc|inlined\)$" >> $expected
+	expected[0]='ping[][0-9 \.:]+'"$event_name"': \([[:xdigit:]]+\)'
+	expected[1]='.*inet_pton\+0x[[:xdigit:]]+[[:space:]]\('"$libc"'|inlined\)$'
 	case "$(uname -m)" in
 	s390x)
-		eventattr='call-graph=dwarf,max-stack=4'
-		echo "text_to_binary_address.*\+0x[[:xdigit:]]+[[:space:]]\($libc|inlined\)$" >> $expected
-		echo "gaih_inet.*\+0x[[:xdigit:]]+[[:space:]]\($libc|inlined\)$" >> $expected
-		echo "(__GI_)?getaddrinfo\+0x[[:xdigit:]]+[[:space:]]\($libc|inlined\)$" >> $expected
-		echo "main\+0x[[:xdigit:]]+[[:space:]]\(.*/bin/ping.*\)$" >> $expected
+		eventattr='call-graph=dwarf,max-stack='"$maxstack"
+		expected[2]='text_to_binary_address.*\+0x[[:xdigit:]]+[[:space:]]\($libc|inlined\)$'
+		expected[3]='gaih_inet.*\+0x[[:xdigit:]]+[[:space:]]\('"$libc"'|inlined\)$'
+		expected[4]='(__GI_)?getaddrinfo\+0x[[:xdigit:]]+[[:space:]]\('"$libc"'|inlined\)$'
+		expected[5]='main\+0x[[:xdigit:]]+[[:space:]]\(.*/bin/ping.*\)$'
 		;;
 	ppc64|ppc64le)
-		eventattr='max-stack=4'
-		echo "gaih_inet.*\+0x[[:xdigit:]]+[[:space:]]\($libc\)$" >> $expected
-		echo "getaddrinfo\+0x[[:xdigit:]]+[[:space:]]\($libc\)$" >> $expected
-		echo ".*(\+0x[[:xdigit:]]+|\[unknown\])[[:space:]]\(.*/bin/ping.*\)$" >> $expected
+		eventattr='max-stack='"$maxstack"
+		expected[2]='gaih_inet.*\+0x[[:xdigit:]]+[[:space:]]\('"$libc"'\)$'
+		expected[3]='getaddrinfo\+0x[[:xdigit:]]+[[:space:]]\('"$libc"'\)$'
+		# Line valid with glibc 2.35.x with fedora 36
+		expected[4]='.*(\+0x[[:xdigit:]]+|\[unknown\])[[:space:]]\(.*/bin/ping.*\)$'
+		# New line introduced with glibc 2.36.x with fedora 37, replaces previous line
+		expected[5]='[[:xdigit:]]+[[:space:]](\[unknown\]|main)\+0x[[:xdigit:]]+.*\(.*/bin/ping.*\)$'
 		;;
 	*)
-		eventattr='max-stack=3'
-		echo "getaddrinfo\+0x[[:xdigit:]]+[[:space:]]\($libc\)$" >> $expected
-		echo ".*(\+0x[[:xdigit:]]+|\[unknown\])[[:space:]]\(.*/bin/ping.*\)$" >> $expected
+		maxstack=3
+		eventattr='max-stack='"$maxstack"
+		expected[2]='getaddrinfo\+0x[[:xdigit:]]+[[:space:]]\('"$libc"'\)$'
+		# Line valid with glibc 2.35.x with fedora 36
+		expected[3]='.*(\+0x[[:xdigit:]]+|\[unknown\])[[:space:]]\(.*/bin/ping.*\)$'
+		# New line introduced with glibc 2.36.x with fedora 37, replaces previous line
+		expected[4]='[[:xdigit:]]+[[:space:]](\[unknown\]|main)\+0x[[:xdigit:]]+.*\(.*/bin/ping.*\)$'
 		;;
 	esac
 
@@ -60,16 +68,34 @@ trace_libc_inet_pton_backtrace() {
 	perf record -e $event_name/$eventattr/ -o $perf_data ping -6 -c 1 ::1 > /dev/null 2>&1
 	perf script -i $perf_data > $perf_script
 
+	# To make the call stack checking more robust to changes in the glibc
+	# just check that each probe output line appears in the expected
+	# patterns array.
+	# This scheme does not check the sequence as before but tests
+	# that every line in the call stack is expected. Considering the
+	# long patterns this should be save too.
 	exec 3<$perf_script
-	exec 4<$expected
-	while read line <&3 && read -r pattern <&4; do
-		[ -z "$pattern" ] && break
-		echo $line
-		echo "$line" | egrep -q "$pattern"
-		if [ $? -ne 0 ] ; then
-			printf "FAIL: expected backtrace entry \"%s\" got \"%s\"\n" "$pattern" "$line"
+
+	# Number of input lines to check, take value from max-stack attribute
+	while read line <&3; do
+		[ "$idx" -ge "$maxstack" ] && break
+		[ -z "$line" ] && break
+
+		hit=0
+		for pattern in "${expected[@]}"
+		do
+			# echo PATTERN "$pattern"
+			echo "$line" | egrep -q "$pattern"
+			[ $? -eq 0 ] && { hit=1; break; }
+		done
+		if [ "$hit" -eq 1 ]
+		then
+			printf "HIT: \"%s\"\n" "$line"
+		else
+			printf "FAIL: missing backtrace entry for line \"%s\"\n" "$line"
 			return 1
 		fi
+		((++idx))
 	done
 
 	# If any statements are executed from this point onwards,
