#!perl -slw use strict; use vars qw[$NEW_A]; use Data::Dumper; use Inline::Files '-backup'; local $,=', '; my %b = map{ ( '1'.$_->[0] => 1, '4'.$_->[1] => 1, ) } map{ [ (split':')[0,3] ] } ; my %c = map{ $_ => 1 } map{ (split':')[2] } ; #print Dumper \%b, \%c; open NEW_A, "> $NEW_A" or die $!; while() { chomp; my @fields = split':'; print( "Removing '$_' from FILE_A because field 1:'$fields[0]' not in FILE_B"), next if !exists $b{ '1'.$fields[0] }; print( "Removing '$_' from FILE_A because field 4:'$fields[3]' not in FILE_B"), next if !exists $b{ '4'.$fields[3] }; print( "Removing '$_' from FILE_A because field 3:'$fields[2]' not in FILE_C"), next if !exists $c{ $fields[2] }; print NEW_A $_, $/; } __FILE_A__ 1:*:Z:A:* 2:*:Y:B:* 3:*:X:C:* 4:*:Z:D:* 5:*:Y:E:* 6:*:X:F:* 7:*:T:G:* __FILE_B__ 1:*:*:A:* 2:*:*:B:* 3:*:*:C:* 4:*:*:D:* 5:*:*:E:* 6:*:*:F:* __FILE_C__ *:*:Z:*:* *:*:Y:*:* *:*:T:*:* __NEW_A__ 1:*:Z:A:* 2:*:Y:B:* 4:*:Z:D:* 5:*:Y:E:*