#!/usr/bin/perl use warnings; use strict; open (DATA, "dic") || die "Error opening the input file\n"; print "Reading mapping file\n"; print "----------------------------\n"; open (INFILE, "trial.txt") || die "Error opening the input file\n"; print "Reading input file\n"; print "----------------------------\n"; my %dict; while (my $line = ) { my $old_string = $line; while ( ) { my ( $key, $val ) = /^(\d+)\s+(\w+)/; $dict{ $val } = $key; } my $cc = join '', keys %dict; my ( $min ) = my ( $max ) = map length, keys %dict; for ( map length, keys %dict ) { $min = $_ if $min > $_; $max = $_ if $max < $_; } my $pattern = qr/\b([$cc]{$min,$max})\b/; ( my $new_string = $old_string ) =~ s/$pattern/ exists $dict{ $1 } ? $dict{ $1 } : $1 /eg; print "$new_string\n"; } close (INFILE); close (DATA); #### Reading mapping file ---------------------------- Reading input file ---------------------------- april 1168 0.06781456 Use of uninitialized value in concatenation (.) or string at seek.pl line 29, line 19969. Use of uninitialized value in concatenation (.) or string at seek.pl line 29, line 19969. Unmatched [ in regex; marked by <-- HERE in m/\b([ <-- HERE ]{,})\b/ at seek.pl line 29, line 19969.