use strict; use warnings; use feature 'say'; while () { say $1 if /#augment:(?:A|B)(.*)/; } __DATA__ First line of the file used for filler #augment:A Something One Another line of text for filler #augment:B Something Two Last line of the file used for filler