my $count=0; while ($pointer = $sth->fetchrow_hashref) { ++$count; $type=$pointer->{'TYPE'}; $number =$pointer->{'NUMBER'}; $line =$pointer->{'LINE'}; if($count > 1) { print "**** $number **** \n"; # If there is more than one value it will start to print from the second one and it will still go to the ELSE I need to print all the values here and exit from it, just need to know what is the best way to do it. }else { print $number; } } #end of the while