use strict; use warnings; # merger v1.2.1 open my $B, '<', 'file_B.txt' or die "Cannot open file_B: $!"; my %functions; my $i =0; while (my $line = <$B>) { chomp $line; $line =~ s/(\d+)\s//; $functions{$1} = $line; } close $B; open my $A, '<', 'file_A.txt' or die "Cannot open File_A: $!"; open my $C, '>', 'File_C.txt' or die "Cannot open File_C; $!"; my $prev_id; while (my $line = <$A>){ my ($id,$code) = split /\s+/, $line; if (!defined $prev_id or $id ne $prev_id){ print {$C} "\n" if defined $prev_id; print {$C} "$id"; $prev_id = $id; } else { print {$C} "," } print {$C} "\t$functions{$code}"; } print {$C} "\n"; close $C; close $A; exit 0;