my %tasks = ( templog => { interval => 5, # seconds code => sub { if (-e $templog) { ... } else { ... } }, }, backup => { interval => 2 * 60 * 60, # 2h code => \&DB_Backup, }, ); while (1) { for (keys %tasks) { my $since = time - ($tasks{$_}{last} || time); if ($since >= $tasks{$_}{interval}) { $tasks{$_}{code}->(); $tasks{$_}{last} = time; CheckTS(); # Or put this in each sub { } } } sleep 1; # See note }