Because you use single quotes instead of double quotes.
Perl doesn't interpolate variables enclosed in single quotes, so what you are doing is sending the string '$srceDir' to the shell which will normally be unset (blank) unless you have it set in your environment somewhere.
Try this:
my $find_cmd = "find $srceDir -type f -newermt 2013-02-14 ! -newermt 2013-02-15";
or better this:
my $find_cmd = sprintf
'find "%s" -type f -newermt 2013-02-14 ! -newermt 2013-02-15',
$srceDir;
... care about spaces while find_cmd would be executed under forked sh.
* Important remark *
As @vonbrand rightly commented: perl does offer a lot of libraries for ensuring communication between your program and many other things.
For the file system operation find, perl uses the File library module File::Find, for which a little utility exists find2perl which will translate your find command-line into a little perl script:
$ find2perl -type f -mtime -3 ! -mtime -2;
#! /usr/bin/perl -w
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; #$running_under_some_shell
use strict;
use File::Find ();
# Set the variable $File::Find::dont_use_nlink if you're using AFS,
# since AFS cheats.
# for the convenience of &wanted calls, including -eval statements:
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
sub wanted;
# Traverse desired filesystems
File::Find::find({wanted => \&wanted}, '.');
exit;
sub wanted {
my ($dev,$ino,$mode,$nlink,$uid,$gid);
(($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
-f _ &&
(int(-M _) < 3) &&
! (int(-M _) < 2)
&& print("$name\n");
}
So your need could become something like this:
#! /usr/bin/perl -w
my $srceDir = "/mnt/SDrive/SV/Capture Data/";
my $startDate = "2013-02-14";
my $endDate = "2013-02-15";
use strict;
use File::Find ();
use POSIX qw|mktime|;
use vars qw/*name *dir *prune/;
*name = *File::Find::name;
*dir = *File::Find::dir;
*prune = *File::Find::prune;
my ($sDay,$eDay)=map {
my ($year,$month,$day)=split("-",$_);
(time()-mktime(0,0,0,$day,$month-1,$year-1900))/86400
} ($startDate,$endDate);
sub wanted {
my ($dev,$ino,$mode,$nlink,$uid,$gid);
(($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
-f _ &&
(-M _ < $sDay) &&
! (-M _ < $eDay)
&& print("$name\n");
}
File::Find::find({wanted => \&wanted}, $srceDir );
The best advantage of doing this, instead of open $fh,"find ...|", is that this is very robust; you don't have to care about characters present in filenames (like spaces, quotes, ampersand...).