# modules are usually not "use"d inside subs, but just once at the code start use Text::CSV; sub _moredata_array { my ($datastring, $datasep_cfg) = @_; # Do not/never quote variables if you do not explicitly want to force PV context # e.g. if $datasep_cfg is undefined is means something completely different then # the empty string which it is forced to when quoted my $csv = Text::CSV->new ({ binary => 1, auto_diag => 1, sep_char => $datasep_cfg }); # you can declare $io as lexical (my) in the open call itself # At this point,Text::CSV->error_diag () is undefined, as $csv has not even been used # and opening of the scalar as file handle does not interact with $csv (yet) open my $io, "<:encoding(utf8)", \$datastring or die "Cannot use CSV: $!"; # no need to declare a variable # the return value can possible be a reference to an empty list. think if you want # that. || undef is useless here return $csv->getline ($io); } sub _moredata_hash { my ($datastring, $hashsep) = @_; my $csv = Text::CSV->new ({ binary => 1, auto_diag => 1, sep_char => $hashsep }); open my $io, "<:encoding(utf8)", \$datastring or die "Cannot use CSV: $!"; my %hash; while (my $row = $csv->getline($io)) { my $count = scalar @{$row}; $count % 2 and die "$count is an odd number of keys and values at (@{$row}).\n"; $hash{$row->[0]} = $row->[1]; } scalar %hash ? \%hash : undef; }