in reply to scalar out of a loop

> Is there a way to export a variable out of the foreach, I've googled it, but don't seems to find something

"Exporting" is something completely different, googling won't help here.

Corion was right, but the concept you need to understand is called "scoping" of lexical ("my") variables.

Have a look here: Coping with Scoping.

HTH! :)

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)