On 28.09.2008 10:46, Robert Klemme wrote: > If you use a Hash you can do something like this (proper variable naming > goes a long way in making this readable and understandable): > > counters = Hash.new 0 > > ARGF.each do |line| > line_class = line[/\b(?:IN|OUT|PP|AA)\b/] > raise "Unknown rule" unless line_class > print counters[line_class] += 1, " ", line > end PS: Forgot to mention that you may have to adjust the regexp matching to be more robust. In your case you may want to do line_class = line[/^access-list\s+(IN|OUT|PP|AA)\b/, 1] Cheers robert