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
Use of interval timers may interfere with alarm(), sleep(), and usleep(). In standard-speak the "interaction is unspecified", which means that anything may happen: it may work, it may not.