http://www.perlmonks.org?node_id=910250


in reply to Re^4: Extracting Unique elements
in thread Extracting Unique elements

Just use join instead of a loop:

print FH ref($bar) eq "ARRAY" ? join(',', @$bar) : $bar;