$idx = 1; $team = team a; $idx = 2; $team = team a; $idx = 3; $team = team a; #### team a 1 2 3 #### #CODE STARTS HERE# sub initialize { local ($x) = @_; if ($x == 1) { $idx = &dummyvoid($row->{'idx'}); $team = &dummyvoid($row->{'team'}); } } while ($row = $sth->fetchrow_hashref) { &initialize(2); }