use strict; use warnings; my $IDFILE = 'H_E'; my $AMPFILE = 'a.log'; my $OUTFILE = 'report.lst'; my @id_hits; # loop through the id file to get the prime id from each line and # push it onto the @hits array # open my $IFILE, '<', $IDFILE or die "Could not open $IDFILE: $!"; my @id_hits=map substr($_, 0, 6), <$IFILE>; #print "@id_hits"; # loop through the amp.log find the line matches for the hits in # this @id_hits array. # open my $AFILE, '<', $AMPFILE or die "Could not open $AMPFILE: $!"; my ( $line, $next_line ); my @log = <$AFILE>; while ( @log ) { foreach my $prime_id ( @id_hits ) { $line = shift @log until $line =~ /$prime_id/; undef $line; $next_line = shift @log until $next_line =~ /^AMP-commit/; my $amp_msg = $next_line; undef $next_line; open my $OFILE, '>', $OUTFILE or die "Cannot create report file: $!"; print $OFILE "$prime_id:\t$amp_msg\n" or die "Cannot print to file: $!"; close $OFILE; } }