foreach my $num (@tokens) { my $strBegin = uc substr($num, 0, 3); $date = $months{$strBegin} if exists $months{$strBegin}; }