NB: You say the sub outputs a list, but I assume what you mean is that it outputs a string. Otherwise, this question is moot.
Just split the output on newline. Assuming the subroutine is called subname:
for my $fqdn (split /\n/, subname())
As Brian Roach notes in the comments, the optimal solution is to make the subroutine return a list instead of a string. However, that may not be a viable solution for you. Either way, if you wish to try it, simply add the split at the appropriate place in the subroutine instead. E.g.:
sub foo {
...
#return $string;
return split /\n/, string;
}
If you want to get advanced, you may make use of the wantarray function, which detects in which context the subroutine is called:
sub foo {
...
return $string unless wantarray;
return split /\n/, string;
}
While this is very cute, it can lead to unwanted behaviour unless you know what you are doing.