sub card { my @card_map = qw(zero one two three four five six seven eight nine); # these aren't used, so they should be removed my $guess; my $i = 0; # there is no need for these vars to be global: our $num; our $negative = "negative"; # declare them as lexicals instead my $num; my $negative = "negative"; # declaring $num as lexical you don't need to localize: local($num) = @_; # this works here, but do you really understand what its doing? # hint: list context my ($num) = @_; # this is better my $num = $_[0]: # or this: my $num = shift @_; # commonly shortened (@_ is implicit) to: my $num = shift; # for the rest, notice how much simpler the logic # is in moritz reply above # so putting it all together: sub card{ my $num = shift; my $negative = "negative"; my @card_map = qw(zero one two three four five six seven eight nine); my $return_value; if ($num < 0){ $num = -$num; $return_value = $negative; } $return_value .= "$card_map[$num]"; return $return_value; } # and simplified further: sub card{ my $num = shift; my @card_map = qw(zero one two three four five six seven eight nine); if ($num < 0){ $num = -$num; return "negative $card_map[$num]"; } return $card_map[$num]; }