in reply to A quick date swap from a string

You declare "my $date" twice:
  my $date= shift;
  ...
  my $date;
The second one creates a new lexical with an undefined value. So the subsequent substitution and return are working with undef;