in reply to Accessing secondary elements in array

If I've understood correctly, you could construct a hash keyed by the four columns of interest. If you split the line on whitespace and slice out the columns and join them again with some delimiter (I chose a colon) you construct the key. I have added a line to your "array 2" data with a common "bold part" so you can see that it gets removed.

Note that I have used Data::Dumper so that you can see the lookup hash and resultant @array2. Here's the code.

use strict; use warnings; use Data::Dumper; open my $array1FH, q{<}, \ <<'EOF1' or die qq{open: < HEREDOC 1: $!\n} +; ATOM 2198 SG CYS L 51 39.781 -12.827 5.691 1.00 26.67 ATOM 2199 N MET L 52 37.845 -15.766 5.722 1.00 33.08 ATOM 2200 CA MET L 52 38.312 -17.144 5.674 1.00 33.08 ATOM 2201 C MET L 52 37.329 -18.022 4.901 1.00 33.08 EOF1 my @array1 = <$array1FH>; close $array1FH or die qq{close: < HEREDOC 1: $!\n}; my %array1Lookup = map { join( q{:}, ( split )[ 2 .. 5 ] ), 1 } @array1; print Data::Dumper->Dumpxs( [ \ %array1Lookup ], [ qw{ *array1Lookup } + ] ); open my $array2FH, q{<}, \ <<'EOF2' or die qq{open: < HEREDOC 2: $!\n} +; ATOM 2212 CB MET L 52 17.332 94.112 87.029 1.00 0.00 ATOM 2213 CG MET L 52 18.017 94.866 88.170 1.00 0.00 ATOM 2214 SD MET L 52 18.711 96.457 87.699 1.00 0.00 ATOM 2215 CE MET L 52 17.198 97.429 87.820 1.00 0.00 ATOM 2216 N ARG L 53 19.331 91.671 87.132 1.00 0.00 ATOM 2217 CA MET L 52 19.331 91.671 87.132 1.00 0.00 EOF2 my @array2 = (); while ( <$array2FH> ) { chomp; my $lookupKey = join q{:}, ( split )[ 2 .. 5 ]; next if $array1Lookup{ $lookupKey }; push @array2, $_; } close $array2FH or die qq{close: < HEREDOC 2: $!\n}; print Data::Dumper->Dumpxs( [ \ @array2 ], [ qw{ *array2 } ] );

The output.

%array1Lookup = ( 'C:MET:L:52' => 1, 'N:MET:L:52' => 1, 'CA:MET:L:52' => 1, 'SG:CYS:L:51' => 1 ); @array2 = ( 'ATOM 2212 CB MET L 52 17.332 94.112 87.029 1 +.00 0.00', 'ATOM 2213 CG MET L 52 18.017 94.866 88.170 1 +.00 0.00', 'ATOM 2214 SD MET L 52 18.711 96.457 87.699 1 +.00 0.00', 'ATOM 2215 CE MET L 52 17.198 97.429 87.820 1 +.00 0.00', 'ATOM 2216 N ARG L 53 19.331 91.671 87.132 1 +.00 0.00' );

I hope I have guessed correctly and this is of some help.

Cheers,

JohnGG

Update: Added missing @ sigil to array2 in 2nd paragraph.