my $fh = IO::File->($datafile) or die; #instead of - and you don't need the quotes either my $fh = new IO::File "$datafile";