#!/usr/bin/perl
use 5.016;
use warnings;
use utf8;
binmode STDOUT => ':encoding(utf-8)';

open(my $in, '<:encoding(utf-8)', \(my $dmy = <<'EOL')) or die;
こういった10行で一組のデータの中に 
--- 
市民の... 

yerles 
warrior 
--- 
というパターンが多くあります。 
マッチ検索したいのは 
--- 
市民の... 

dog 
warrior 
--- 
というパターンです。 
"市民"という文字を見つけたら 
2行下に 
"dog"という文字があるならば 
その、"市民の..."を出力して欲しいです。 
EOL

my @pipe = ('', '', '');
while(<$in>){
	chomp;
	push(@pipe, $_);
	shift(@pipe);

	if (/dog/ and $pipe[0] =~ /市民/){
		print $pipe[0], "\n";
	}
}
close($in);
