#!/usr/bin/env perl use strict; use warnings; use autodie; use constant { GENE_FILE => 'pm_1192233_genes.txt', MISSING_FILE => 'pm_1192233_missing.txt', OUT_PREFIX => 'pm_1192233_out_', }; my @ano_files = @ARGV; my ($gene_list, $gene_re) = get_gene_data(GENE_FILE); for my $ano_file (@ano_files) { open my $fh, '<', $ano_file; while (<$fh>) { print { get_out_fh($1) } $_ if /$gene_re/; } } gen_missing_report($gene_list); { my %fh_for; sub get_out_fh { unless (exists $fh_for{$_[0]}) { open $fh_for{$_[0]}, '>', OUT_PREFIX . $_[0]; } return $fh_for{$_[0]}; } sub gen_missing_report { my ($genes) = @_; open my $fh, '>', MISSING_FILE; print $fh "--- START MISSING LIST ---\n"; print $fh "$_\n" for grep { ! exists $fh_for{$_} } @$genes; print $fh "--- END MISSING LIST ---\n"; } } sub get_gene_data { my ($file) = @_; my @list; open my $fh, '<', $file; push @list, $_ while <$fh>; chomp @list; @list = sort { length $b <=> length $a } @list; my $alt = join '|', @list; return (\@list, qr{($alt)}); }