#!/usr/bin/perl use threads; $filename = "/tmp/input.log"; $outputdir = "/var/log/"; $first_event = 1; $position = 0; $time = time(); # Define Timer sub timer { my $counter = 0; while (1) { sleep(1); if ($counter >= 60) { $counter = 0; # #I can't seem to close FILE from the main thre +ad... why? # close (FILE); $outputfile = $outputdir . "log-". time(); open(FILE, "> $outputfile") || die("Can't open + $outputfile to write to"); } $counter++; } } $thr1 = threads->new(\&timer); # Spawn the thread open(TAIL, "tail --follow=name $filename|"); $outputfile = $outputdir . "log-". time(); open(FILE, "> $outputfile") || die("Can't open $outputfile to write to +"); while () { # do some stuff and print to FILE }