open my $pf, '<', $file or die "ERROR: Cannot open input file: $file $!\n"; my $newvar; #chomp (my @array = (<$pf>)); my @array = (<$pf>); foreach (@array) { $newvar .= $_; } #Attempt to capture just one pattern $newvar =~ /(?:#augment:A)(.*)(?:\n)/; say $1; #this works, printed to standard output is: ' Something One' as I hoped for #Attempt to capture just one pattern $newvar =~ /(?:#augment:B)(.*)(?:\n)/; say $1; #this works, printed to standard output is: ' Something Two' as I hoped for #Attempt to capture 2 patterns by combining above regex's $newvar =~ /(?:#augment:A)(.*)(?:\n)(?:#augment:B)(.*)(?:\n)/ ; say $1; say $2; #Does not work - nothing is captured and I get uninitialized value $1 and $2 warnings...