my @match_flds = /(\d{4}) \s (\d{5}) \s (\d{3}) \s (\d{2}) \s (\d{2} \/ \d{2} \/ \d{2}) \s (\d{2} \: \d{2} \: \d{2}) \s (\d{3}) \s (\d{2}) \s (\S+) \s (\d{2}) \s (\d{2}) \s (\d{2}) \s (\d{2}) \s (\w{3}) $ /x ; if (@match_flds) { # now indexes are 1-off from the corresponding numbered # regex vars: e.g., $match_flds[0] is $1, $match_flds[1] is $2, etc. # remap the 15th field using your hash $match_flds[14] = $TOC{ $match_flds[14] }; # print them print join( ' ', @match_flds ), "\n"; }