use warnings; use strict; ; # discard first line/record of data MP_PAIR: while (my $m = ) { my $bad; # badness message from validity checks (empty if ok) die qq{bad M record '$m': $bad} if $bad = bad_M_record($m); defined(my $p = ) or die qq{M record '$m' has no P record}; die qq{bad P record '$p': $bad} if $bad = bad_P_record($p); die qq{bad MP pair '$m'/'$p': $bad} if $bad = bad_MP_pair({M => $m, P => $p}); chomp($m, $p); my $x = $m ^ $p; # detect equal sub-regions # are ' 0 1 0 0 1 1' sequences at end of records the same? next MP_PAIR unless $x =~ m{ \A .{9} (?: \x00\x00){13} \z }xms; do_something_with({M => $m, P => $p}); } # end while MP_PAIR # stubs for validity checking functions. sub bad_M_record { return ''; } sub bad_P_record { return ''; } sub bad_MP_pair { return ''; } sub do_something_with { my ($hr_MP_args, ) = @_; printf qq{M '%s' \nP '%s' \n\n}, @{ $hr_MP_args }{ qw(M P) }; } __DATA__ INDIV 16051347(G-C) 16051497(A-G) 16052239(A-G) 16052513(G-C) 16052618(G-A) 16053659(A-C) 16054667(C-G) HG00096.M 0 0 0 1 1 1 1 1 0 0 0 0 0 HG00096.P 0 0 1 0 0 0 0 1 0 0 0 0 0 HG00097.M 1 1 0 0 0 0 0 0 0 0 0 1 0 HG00097.P 0 0 1 0 0 1 0 1 1 1 0 0 0 HG00099.M 1 1 0 0 0 0 0 0 0 0 0 0 0 HG00099.P 0 0 0 0 1 1 0 0 1 1 0 1 0 HG00100.M 0 0 1 1 1 1 1 1 1 1 1 1 1 HG00100.P 1 1 0 0 0 1 0 0 1 1 0 1 0 HG00101.M 1 1 0 0 0 1 0 0 1 1 0 1 0 HG00101.P 0 0 1 1 1 1 1 1 1 1 1 1 0 HG00102.M 1 1 0 0 0 0 0 0 0 0 0 1 0 HG00102.P 0 0 1 0 0 1 0 1 1 1 0 1 0 EQ99991.M 0 1 0 0 1 1 0 0 0 1 1 1 0 EQ99991.P 0 1 0 0 1 1 0 0 0 1 1 1 0 HG00103.M 0 0 0 0 0 0 0 0 0 0 0 0 0 HG00103.P 1 0 0 0 0 0 0 0 0 0 0 0 0 EQ99992.M 1 0 1 0 1 0 1 0 1 0 1 0 1 EQ99992.P 1 0 1 0 1 0 1 0 1 0 1 0 1 #### c:\@Work\Perl\monks\A1 Transcendence>perl filter_MP_records_1.pl M 'EQ99991.M 0 1 0 0 1 1 0 0 0 1 1 1 0' P 'EQ99991.P 0 1 0 0 1 1 0 0 0 1 1 1 0' M 'EQ99992.M 1 0 1 0 1 0 1 0 1 0 1 0 1' P 'EQ99992.P 1 0 1 0 1 0 1 0 1 0 1 0 1'