in reply to Question regarding perl subroutine

my $ptf_filename; ... if ( $response->is_success ) { ... my $ptf_filename = $data->{PtfFileName}; ... } return $ptf_filename;

There's another problem of masking lexical variable names similar to the one with the  $ua scalar. The first definition of  $ptf_filename before the if-block is masked by another definition of a lexical of the same name within the block. After the if-block, the value of the first lexical (which has never been given any value) is returned. (Technically, I guess this is not a masking problem but a scoping problem, as davies has alluded. It may – or may not – be perfectly valid semantically to define a lexical variable in one scope that has the same name as another lexical in a different scope. See Coping with Scoping.)

Update: Had you been using warnings in the code posted originally, Perl would have warned you about the  $ua problem (this really is a masking problem).

>perl -wMstrict -le "my $x = 1; my $x; print $x; " "my" variable $x masks earlier declaration in same scope at ... Use of uninitialized value $x in print at ...