use strict; use IO::File; my %industries; # Load the industry definition file my $def = new IO::File "def.txt", "r" or die "Can not open file!"; while (<$def>) { if (m/'(.*?)','(.*?)'/) { $industries{$1} = $2; } } undef $def; # close the file # Load the data file my $dat = new IO::File "dat.txt", "r" or die "Can not open file!"; while (<$dat>) { s/('.*?'),('.*?')/$2,$1/g; # swap the items my $id = substr($_, 1, 2); print "'$id','$industries{$id}'|$_"; } undef $dat; #### -- def.txt -- 'BB','Drinks Industry' 'BL','Construction Industry' -- dat.txt -- 'Coffee Suppliers','BB100'|'Tea Suppliers','BB106' 'Plasterers','BL100'|'Fencing Companies','BL102' #### 'BB','Drinks Industry'|'BB100','Coffee Suppliers'|'BB106','Tea Suppliers' 'BL','Construction Industry'|'BL100','Plasterers'|'BL102','Fencing Companies'