my @lines = (<>); my $text = join "", @lines; #### if ($text =~ m/( \(LABEL O 1\))(\n.+?)( \(STOP\)\n)/s) { $labelo1 = $1; $labelo1instructions = $2; print "$labelo1\n NEWLIGINSTRUCTIONS HERE$labelo1instructions"; } else { print "(LABEL O 1)\n NEWLIGINSTRUCTIONS HERE\n"; }