#!/usr/bin/perl use strict; use warnings; my $OUTPATH=''; my $A=''; my $B=''; my $C=''; my %index; open(my $temp_fh, '<', "$OUTPATH/$B") or die("Can't open $B ($!)\n"); MAINLOOP: while(my $line=<$temp_fh>) { while($line=~/(\d+)/gc) { my $value=$1; $value+=0; next if(exists($index{$value})); $index{$value}=$line; next MAINLOOP; } } close($temp_fh); open(my $out_fh, '>', "$OUTPATH/$C") or die("Can't open $C ($!)\n"); open(my $in_fh, '<', "$OUTPATH/$A") or die("Can't open $A ($!)\n"); while(my $line = <$in_fh>) { my $value=substr($line,0,20); $value+=0; if(exists($index{$value})) { print $out_fh $index{$value}; next; } print $out_fh $line; } close($in_fh); close($out_fh);