my $sum=0; while (<>) { ... if ($blah) { my $foo=somefunc; something($foo); } }