in reply to manipulating file contents

I get the impression that you haven't tried looking at tutorials about regular expressions yet. You should do that -- it's not so complicated really. There's "perldoc perlretut" on your command line, and numerous tutorials that can be found on the web (including in our own Tutorials area).

So look things up to see why something like this ought to do what you want:

while (<>) { next if (/^#/); s/(Key [0-5] 0x\w{14}).*/$1/; } continue { print }