use AnyEvent; # Used for Main Loop my $main = AnyEvent->condvar; print scalar localtime, "\n"; # After 5 seconds my $t; $t = AnyEvent->timer( after => 5, cb => \&print_time ); # Enter Main Loop $main->recv; sub print_time { sleep 10; print scalar localtime, "\n"; $t = AnyEvent->timer( after => 5, cb => \&print_time ); }