TIMTOWTDI... I would use a
foreach loop instead of
while. foreach will build the list before the loop runs
then iterate, so once the list is finished the loop will exit. One call to the subroutine, no temporary variables, ie:
foreach ($response->content =~ /pcd=BT(\d+)/g) {
print $count++,$1,"\n";
}