#!/usr/bin/perl -l use warnings; use strict; use Inline::Files; my %file1; while () { next if /^\s+$/; my ( $key, $value ) = split; $file1{$key} = $value; } my $str_union; my $str_inter; while () { next if /^\s+$/; my ( $key, $value ) = split; if ( $file1{$key} ) { $str_union .= $_; } else { $str_inter .= $_; } } print "This goes to File 3\n", $str_union, "\nThis goes to File 4\n", $str_inter; __FILE1__ EC:1.1.1.42 isocitratedehydrogenase EC:1.1.1.44 6-phosphogluconatedehydrogenase EC:1.1.1.49 glucose-6-phosphate1-dehydrogenase __FILE2__ EC:1.1.1.42 isocitratedehydrogenase EC:1.1.1.44 6-phosphogluconatedehydrogenase EC:1.1.1.49 glucose-6-phosphate1-dehydrogenase EC:1.11.1.9 glutathioneperoxidase EC:2.5.1.16 spermidinesynthase EC:6.3.1.8 glutathionesynthase