use IO::YAML; my $yaml_fh = IO::YAML->new( handle => \*DATA, mode => '<', auto_load => 0, ) or die "Can't open ...: $!"; while ( not $yaml_fh->eof ) { my $yaml = <$yaml_fh>; # Skip comment-only blocks. Is it a bug that this ever happens? next if /\A(?:^#[^\n]*\n)+\z/m; } __DATA__ # this is a comment about the 40MB of YAML documents to follow --- foo: 1 bar: 2