그냥 간단히 다음과 같이 해도 될 것 같네요 $text = join('', <>); while($text =~ m{(^start(.*?)^return\s+(\d+))}gms) { print "$1\n\n" if ($3 >=5); }