local $/; while (<>) { while (/^name\n-+\n(.*)/mg) { # stuff you want is in "$1" } }