$fn="rituko_n";

open(IN,$fn.".ksp");
$pfix=0;
$mflg=0;
$cou=-1;

while(<IN>){
	if(/\[Item\d+\]/){
		if($head eq ""){$head=$stack;}
		else{
			if($mflg==1){&put_syori();}
			else{$mflg=0;}
			$stack=~s/\[Item\d+\]/\[Item$cou\]/;
			$str.=$stack;
		}
		$stack="";
		$cou++;
	}

	s/;ref=\d+/;ref=0/;
	$stack.=$_;
	if(/=動画読み込み/ && $mflg==0){
		$mflg=1;
	}

}

$stack=~s/\[Item\d+\]/\[Item$cou\]/;
$str.=$stack;
$cou++;
&put_syori();

sub put_syori(){
	$pfix++;
	open(OUT,">${fn}_m$pfix.ksp");

	$mflg=2;
	$head=~s/イムライン\=\d+/イムライン\=$cou/;
	print OUT "$head$str";
	close(OUT);
	$str="";
	$cou=0;
}
