Rework perl5 compiler and linker flags

This fixes perl on cygwin. Probably on other platforms too.