in reply to Check for 'and'

Maybe you seeking something like this:


#!/usr/bin/perl -w
use strict;
use 5.010;
my $str=<<TEXT;
{TAG}
0012310002 and 0012310003
{COUNT}
000000
{COUNT2}
000000 and 100001
TEXT
my %strh = $str=~ /({.+?}|^{}+)/sg;
my @and_contain = grep $strh{$_} =~ /and/,keys %strh; 
say join(' and ',@and_contain),' is 1';

Output:

{COUNT2} and {TAG} is 1

Replies are listed 'Best First'.
Re^2: Check for 'and'
by Anonymous Monk on Aug 13, 2009 at 04:33 UTC
    #!/usr/bin/perl use warnings; use strict; my $save; while (<DATA>) { if (/([^{TAG}]*)/) { $save = $1; print $save; } } __DATA__ {TAG} 0012310002 and 0012310003 {COUNT} 000000 {COUNT2} 000000 and 100001 {TAG} 2304854
    How to print the value of only {TAG}. Now the output prints all the values like, 0012310002 and 0012310003
    000000
    000000 and 100001
    2304854
    So how to print only 0012310002 and 0012310003
    and 2304854
    which of {TAG} values