in reply to Help with fork, read and write from a pipe
And maybe if you're using a Unix/Linux environment you can do the first part of this task with the shell ... simply piping the stats program's input into the STDIN of another script that say does a sleep 30*60 followed by a tail -n 30 ... which output is then piped (by the main script) into the actual CSV-conversion (Perl?) routine. This pushes a lot of the complexity of the task out of the domain of Perl and into an environment which is really set up to do this sort of thing. A "pure-Perl solution" is not the only way to do it. Worth considering.