Dingo's solution is a good one [edit: Ned Batchelder's explanation is even better], but here's another one which I think is neat: use closures! If that sounds like a "big word" to you, don't worry. The concept is simple:
def make_matching_function():
matcher = re.compile(r"foo\dbar\d")
def f(line):
return matcher.match(line)
return f
contains_text_of_interest = make_matching_function()
make_matching_function is called only once, and therefore the regex is compiled only once. The function f, which is assigned to contains_text_of_interest, knows about the compiled regex matcher because it's in the surrounding scope, and will always know about it, even if you use contains_text_of_interest somewhere else (that's closures: code that takes the surrounding scope with it).
Not the most Pythonic solution to this problem, surely. But it's a good idiom to have up your sleeve, for when the time is right :)