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.


In reply to Re: Accessing secondary elements in array by johngg
in thread Accessing secondary elements in array by chavanak

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.