use strict; use warnings; use JSON; use Time::Local; my ($hh, $mm) = (15, 20); # 15:20 while ( my $data = ) { my $struct = from_json( $data ); if ( my @res = filter_data_hh_mm( $struct, $hh, $mm ) ) { # ... do something print "Matches: $hh:$mm: [ " .gmtime( $_->[0] ) . ".." . gmtime( $_->[1] ) . " ]\n" for ( @res ); } } sub filter_data_hh_mm { my ($struct, $hh, $mm) = @_; my @res; for my $line ( @{ $struct->{aaData} } ) { # match if begin is before begin-day HH:MM:59 and # if end is after end-day HH:MM:00 if ( $line->[0] <= epoch_at_hhmmss( $line->[0], $hh, $mm , 59) and epoch_at_hhmmss( $line->[1], $hh, $mm , 0) <= $line->[1] ) { push @res, $line; } } return @res; # matching lines or () } sub epoch_at_hhmmss { my ( $epoch, $hh, $mm, $ss ) = @_; #-- use localtime(), timelocal() if $hh:$mm is in localtime # or adjust $hh:$mm to UTC/GMT accordingly my @epoch0 = gmtime( $epoch ); @epoch0[0..2] = ($ss, $mm, $hh); return timegm( @epoch0 ); } __DATA__ {"DisplayRecords":"12","Records":"12","sColumns":"startTime,endTime,remoteNode,srcIP,srcPort,destIP,destPort,egress,ingress","aaData":[["1375976271","1375976430","LAN","D0:05:FE","172.20.30.2",1093,"172.20.28.2",1330,"1034,348","0,0"],["1375976246","1375976404","LAN","D0:05:FE","172.20.30.2",1092,"172.20.28.2",1327,"1034,348","0,0"],["1375976191","1375976381","LAN","D0:05:FE","172.20.30.2",1091,"172.20.28.2",1324,"1034,348","0,0"],["1375976171","1375976314","LAN","D0:05:FE","172.20.30.2",1090,"172.20.28.2",1321,"1034,348","0,0"],["1375976144","1375976302","LAN","D0:05:FE","172.20.30.2",1089,"172.20.28.2",1319,"1034,348","0,0"],["1375975155","1375976089","LAN","D0:05:FE","172.20.30.2",1085,"172.20.28.2",1278,"1034,348","0,0"],["1375975194","1375975352","LAN","D0:05:FE","172.20.30.2",1086,"172.20.28.2",1281,"1034,348","0,0"],["1375974693","1375974835","LAN","D0:05:FE","172.20.30.2",1083,"172.20.28.2",1271,"1034,348","0,0"],["1375974668","1375974827","LAN","D0:05:FE","172.20.30.2",1081,"172.20.28.2",1268,"1034,348","0,0"],["1375974691","1375974821","LAN","D0:05:FE","172.20.30.2",1082,"172.20.28.2",1270,"0,0","0,0"],["1375881371","1375881561","LAN","D0:05:FE","172.20.30.2",1055,"172.20.28.2",1122,"1034,348","0,0"],["1375881410","1375881540","LAN","E0:05:AE","172.20.30.2",1056,"172.20.28.2",1125,"0,0","0,0"]]}