Replace the "#" sign in front of the frame number to make it more convenient to sort a collection of stacks by frame number during post-processing.
For example:
  cat my_stack_traces.out | stack_trace_filter.regexp_match_on_whole_stack.pl 'interesting_pattern' | sort -n -k2 | uniq -c
Refactor to separate the iteration from the behavior.  No functional changes.