#!/usr/bin/perl

use strict;
use warnings;

sub FixCase ($);
sub FixCases ($);
sub Main ();

my (%special) = (
  'Mcgrew' => 'McGrew',
  );

Main;

sub FixCase ($) {
  my $s = shift;
  $s = ucfirst lc $s;
  $s = $special{$s} if exists $special{$s};
  return $s;
  }

sub FixCases ($) {
  my $s = shift;
  $s =~ s/([a-zA-Z]+)/FixCase $1/ge;
  return $s;
  }

sub Main () {
  for my $ARGV (@::ARGV) {
    open my $ifh, '<', $ARGV or die;
    open my $ofh, '>', "$ARGV-new" or die;
    while (<$ifh>) {
      s/^(\D+)/FixCases $1/e;
      print $ofh $_;
      }
    close $ifh;
    close $ofh;
    rename "$ARGV-new", $ARGV;
    }
  }
