I would use split.
#!/usr/bin/perl use Modern::Perl; use Data::Dumper; my @lines = ( "ATOM 1276 CB ASP B 63 52.957 58.788 67.683 1.00 44.59 C", "ATOM 1280 N GLY B 64 52.075 55.496 66.522 1.00 35.29 N", "ATOM 1281 CA GLY B 64 51.005 54.534 66.322 1.00 32.64 C", "ATOM 1282 C GLY B 64 49.693 55.103 65.854 1.00 30.87 C", "ATOM 1283 O GLY B 64 48.630 54.545 66.092 1.00 27.93 O", "ATOM 1284 N LYS B 65 49.739 56.255 65.189 1.00 31.10 N", "ATOM 1285 CA LYS B 65 48.527 56.912 64.720 1.00 33.91 C", "ATOM 1286 C LYS B 65 48.629 57.147 63.216 1.00 32.04 C", "ATOM 1287 O LYS B 65 49.675 57.571 62.721 1.00 31.87 O", ); my @wants; for my $line (@lines) { push @wants, join ' | ', (split " ", $line)[3,6,7,10,11]; } print Dumper(\@wants);

In reply to Re: newbie need help with a simple code by kielstirling
in thread newbie need help with a simple code by perlmonk007

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.