http://qs321.pair.com?node_id=1211770


in reply to Check multiple lines exist in a record

You could read each record into an array, and check it as a unit:

#!/usr/bin/env perl use strict; use warnings; use feature qw(say); use List::Util qw(first); my $rec_no = 0; my @record; my $msisdn; while(<>){ chomp; if(/^<SUBBEGIN/){ @record = ($_); $msisdn = undef; say "Found record: ", ++$rec_no; next; }elsif(/^<SUBEND/){ push @record, $_; check_record(\@record); @record = (); }elsif(/^\s*MSISDN=(\d+);/){ $msisdn = $1; say "Record $rec_no: MSISDN = $msisdn"; }else{ push @record, $_; } } exit 0; sub check_record { my $listref = shift; if( first {/^\s*CF=(CFU-TS10-ACT-(NONE|\d+))/} @{$listref} and first {/^\s*CF=(CFB-TS10-ACT-(NONE|\d+))/} @{$listref} ){ say "this case is found here ....."; } }

It's a bit of a brute-force solution, but it should work.

Sample output:

$ ./t.pl Found record: 1 Record 1: MSISDN = 1234567890 this case is found here ..... Found record: 2 Record 2: MSISDN = 1234567890 this case is found here .....