in reply to File Writing and newline

Maybe you could try the following instead of chomp:
$foreach =~ s/\r?\n$//g;

Best regards,
perl -e "$_=*F=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print"