Perl 5.21.1 compat

Fixes compilation errors and silences deprecation warnings introduced in Perl 5.21.1.

A small bug-fix is also included in related code.