use warnings; use strict; use Async::Event::Interval; open my $fh, '>', 'test.log' or die $!; my $count = 1; my $e = Async::Event::Interval->new( 1, sub { print $fh "in event: $count\n"; $count++; } ); $e->start; for (0..3){ print $fh "write to file in main\n"; sleep 1; } $e->stop;