in reply to listen to a midi keyboard
I'd recommend looking at software that can export to lilypond. I hesitate to mention Rosegarden (Linux-only) since it was terribly crashy and dog-slow the last time I tried it... But hmm, Denemo looks promising. It even uses lilypond under the hood.
Besides, the MIDI-related Perl modules I can find on CPAN seem to be mostly about reading and writing .midi files, or writing to a MIDI device (i.e. playing such a file), and pretty much nothing about reading from a MIDI device. Maybe MIDI::ALSA or Win32API::MIDI can do something?