I understand that it is not safe to use sleep and a timer at the same time within Perl code. My sample uses POSIX timers and alarm. https://www.febo.com/pages/perl_alarm_code/
At the same time: this code works fine for other types of work, like here: https://github.com/kronometrix/recording/blob/master/bin/linux/cpurec