in reply to Condition on multiple lines and big file

No need to slurp the file. Process it line by line, remembering just the name:
my $name = q(); while (<>) { my @cols = split; if ('I-GPE' eq $cols[-1]) { $name .= $cols[0] . ' '; } else { print $name, "\n" if chop $name; $name = $cols[0] . ' '; } } # Do not forget to output the last name. chop $name; print "$name\n";
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ