use strict; use warnings; my @events = qw(1+ 3+ 4- 5+ 5+ 6- 6- 6- 9+ 10-); my $lastEpoch = 0; my $conections = 0; for (@events) { my ($epoch, $event) = /(\d+)(.)/; print "$lastEpoch: $conections\n" if $lastEpoch and $lastEpoch != $epoch; $event eq '+' ? ++$conections : --$conections; $lastEpoch = $epoch; } print "$lastEpoch: $conections\n"; #### 1: 1 3: 2 4: 1 5: 3 6: 0 9: 1 10: 0