in reply to mixing perl & shell style & speed

Am I bad person for mixing shell and perl this way?

Nah. But quicky scripts have a way of escaping into the wild, where people become dependent on them and howl when they break. That's one reason to do more in Perl.

Consider changing     my $key=`cat $file`; into

open(K, "<$file") or die "$file: $!\n"; my $key = do { local $/; <K> }; close(K); chomp($key);
Doing it all in Perl protects against someone having a cat in an unexpected place in their PATH.