#! perl -slw use strict; use threads; use threads::shared; my $filename = "/tmp/input.log"; $outputdir = "/var/log/"; my $first_event = 1; my $position = 0; my $time = time(); my $timerFlag : shared # Define Timer sub timer { my $counter = 0; while (1) { sleep(1); if ($counter >= 60) { $counter = 0; lock $timerFlag; $timerFlag = 1; } $counter++; } } my $thr1 = threads->new(\&timer); # Spawn the thread open(TAIL, "tail --follow=name $filename|") or die "TAIL : $!"; my $outputfile = $outputdir . "log-". time(); open(FILE, "> $outputfile") or die("Can't open $outputfile to write to $!"); while () { if( $timerFlag ) { lock $timerFlag; $timerFlag = 0; close FILE or die $!; $outputfile = $outputdir . "log-". time(); open(FILE, "> $outputfile") or die("Can't open $outputfile to write to $!"); } print( FILE $_ ) or die "Writing to FILE : $!"; }