#!/usr/bin/perl use strict; use warnings; use 5.010; my %recs; while () { my ($time, $mode, $value) = /(\d\d:\d\d:\d\d)\.\d{3} .*? (?: (Pending|Gap) (?:\sdetect\son\s | =)? ([\d.:]+) ) /x; next if !defined $time || !defined $mode; if ($mode eq 'Pending') { $recs{$time}{Pending} = $value; next; } ++$recs{$time}{Gaps}{$value}; } for my $rec (map {$recs{$_}} sort keys %recs) { my $pend = "Pending=$rec->{Pending}\n"; print join $pend, map {"Gap detect $_ "} sort keys %{$rec->{Gaps}} if exists $rec->{Gaps}; print $pend; } __DATA__ 2011-04-03 09:37:12.129 (INFO, ICELineHandler.cpp:339) Product Def MarketID 90120253, Symbol 'BRN FMU0012_OMCA0000118502081312' 2011-04-09 21:32:15.525 3509,3523: Gap detect on 233.156.208.41:20041 from 2746318 to 2746373, moving to next message 2011-04-09 21:32:15.585 3509,3523: Gap detect on 233.156.208.41:20041 from 2746420 to 2746475, moving to next message 2011-04-09 21:32:15.639 3509,3522: Received data on ConnectionICE-Options. Pending=214044. 2011-04-03 09:37:12.129 (INFO, ICELineHandler.cpp:339) Product Def MarketID 90120253, Symbol 'BRN FMU0012_OMCA0000118502081312' #### Gap detect 233.156.208.41:20041 Pending=214044.