my %month_nums; for (my $i = 0; $i <= $#months; $i++) { $month_nums{$month[$i]} = $i; } # This creates a hash of 'Jan' => 0, 'Feb' => 1, etc. sub change_month_to_num { my $month = shift; return $month_nums{$month} + 1; }