Question: During the startup of a Linux AMI, I would like to download some data (like the sun java libraries and some proprietary software) from an S3 bucket while initializing my EC2 connection. I notice that one way to do this is to use s3cmd. BUT, how do I get the configuration file for s3cmd .s3cfg from S3?

Also, let me also know if there is a better way to connect to S3 storage during init.

Thanks!

Answer: 
Pure Perl solution, including splitting `$code_search`, globbing the filenames, and matching the patterns only at the beginnings of words:

```
use List::MoreUtils qw{ all };

my @words = ($code_search =~ m/\S+/g);

for my $fn (glob('*_Codes.txt')) {
    open my $f, '<', $fn || die "Can't open: $!";

    while (defined(my $line = <$f>)) {
        if (all { $line =~ m{\b\Q$_\E}is } @words) { print $line }
    }

    close $f;
}

```

If you don't want to depend on List::MoreUtils, then change the 'if' to:

```
        if (!grep { $line !~ m{\b\Q$_\E}is } @words) { print $line }

```

— a bit harder to read, but only uses perl builtins.
While Skolor's answer is completely appropriate, here's a slightly different approach, making use of the [smart match operator](http://perldoc.perl.org/perlsyn.html#Smart-matching-in-detail) (which is available in Perl version 5.10 or greater). If the lines of your text file are really long and if you don't have a lot of words to check against the lines, this might be a quicker approach (emphasis on "might").

```
use strict;
use warnings;

my @query_words=qw(204 test leg);

open(my $read,"<","input_file") or die $!;

while(<$read>)
{
  chomp; #get rid of trailing newline
  my @words=split(/\s+/,$_); #split on spaces to get actual words

  foreach my $q (@query_words)
  {
    if($q~~@words) #If we have a match, print and exit the loop.
    {
      print "$_\n";
      last;
    }
  }
}

close($read);

```