in reply to "if" in a my declaration statement causes problem

As other people have said - i would set the value to nothing at the very start of the loop. Then initialise it to the input value after that so its a clean value each time. BUT, would set the variable after the condition is true:
sub mehtod($) { my $y = @_; my $x = ""; # or my $x = 0; # then if(/expression/) { $x = $y; } }

Thats my preferable way of doing thins though, which does exactly the same as yours but means 3 extra line of code - ooooooh!