after_count should be simplified like so:

    count = lines.count {|line| lline.match(regex)}