$a = "foo 123 bar"; if ($a =~ m{\d+}xms) { # code that returns 4, the position of 123 }