if($page =~ m/\bword\b\s+.{4}(\d{5})/) { print "The number is $1"; } else { print "No match"; }