IO-Interactive

 view release on metacpan or  search on metacpan

t/busy.t  view on Meta::CPAN

use IO::Interactive qw( busy );

print "1..2\n";

*ARGV = *DATA;

my $fh = busy {
    print "ok 1\n";
    sleep 3;
};

print <$fh>;
print <ARGV>;

__DATA__
ok 2



( run in 3.075 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )