in reply to processing a list of events

Something like this?

#!/usr/bin/perl # http://perlmonks.org/?node_id=1125305 use strict; $_ = join '', <DATA>; print "$1 to $3 := ", $4 - $2, "\n" while /^(.*) (.*)\n(?:\1 .*\n)*(?= +(.*) (.*))/gm; __DATA__ a 123 a 125 b 127 a 129 a 130 b 131 a 132 b 133

Produces:

a to b := 4 b to a := 2 a to b := 2 b to a := 1 a to b := 1