use Modern::Perl; use Date::Calc qw/Date_to_Time/; my $duration = 10 * 60; my $fileName = 'data.txt'; open my $fh, '<', $fileName or die "Unable to open file: $!"; for ( ; ; ) { my ( $first, @lines ); while ( my $line = <$fh> ) { my ( $date, $time, $values ) = split ',', $line, 3; my @dateTime = "$date $time 0" =~ /(\d+)/g; my $timeInSecs = Date_to_Time @dateTime; $first = $timeInSecs unless $first; push @lines, "$timeInSecs\t$values"; last if $timeInSecs - $first >= $duration; } # Start work with chunk of lines in array # do { /(\S+)\t(\S+)/; say "Seconds: $1; Values: $2" } for @lines; say '----------'; # # End work with chunk of lines in array last if eof $fh; } close $fh; #### Seconds: 1294953900; Values: 1.33508,1.33524,1.33470,1.33494,391 Seconds: 1294954020; Values: 1.33508,1.33524,1.33470,1.33494,391 Seconds: 1294954200; Values: 1.33494,1.33506,1.33447,1.33453,318 Seconds: 1294954320; Values: 1.33494,1.33506,1.33447,1.33453,318 Seconds: 1294954500; Values: 1.33453,1.33483,1.33417,1.33434,426 ---------- Seconds: 1294954620; Values: 1.33453,1.33483,1.33417,1.33434,426 Seconds: 1294954800; Values: 1.33434,1.33468,1.33417,1.33467,309 Seconds: 1294954920; Values: 1.33434,1.33468,1.33417,1.33467,309 Seconds: 1294955100; Values: 1.33471,1.33493,1.33465,1.33465,233 Seconds: 1294955220; Values: 1.33434,1.33468,1.33417,1.33467,309 ---------- Seconds: 1294955400; Values: 1.33465,1.33475,1.33443,1.33463,184 Seconds: 1294955520; Values: 1.33465,1.33475,1.33443,1.33463,184 Seconds: 1294955700; Values: 1.33463,1.33519,1.33463,1.33493,344 Seconds: 1294955820; Values: 1.33465,1.33475,1.33443,1.33463,184 Seconds: 1294956000; Values: 1.33494,1.33563,1.33489,1.33524,318 ---------- Seconds: 1294956120; Values: 1.33494,1.33563,1.33489,1.33524,318 Seconds: 1294956300; Values: 1.33524,1.33551,1.33512,1.33549,182 ----------