#!/usr/bin/perl use warnings; use strict; open( my $out_fh, ">", "output.txt" ) || die "Can't open the output file for wri ting: $!"; open( my $address_fh, "<", "Address.txt" ) || die "Can't open the address file: $!"; my %lookup = map { chomp; split( /,/, $_, 2 ) } <$address_fh>; open( my $file_fh, "<", "File.txt" ) || die "Can't open the file.txt file: $!"; while (<$file_fh>) { my @line = split; for my $char ( @line ) { ( exists $lookup{$char} ) ? print $out_fh " $lookup{$char} " : print $ou t_fh " $char "; } print $out_fh "\n"; }