I have never worked with WWW::Mechanize but glancing over its documentation I see a content method that could be used to save the content to a scalar and if you do that, then I'd use the index function instead of grep to test for the existence of what you need.