A few other things:
When you read the filename from STDIN it will include a trailing new-line character, so get ride of it with :
chomp $filename;When reporting an error from an
open (or any other system related function) include the system error held in $!, so you know why it failed:
open (READFILE, $filename)|| die "Failed to opne $filename: $!";
There is plenty more to do, but I suggest you get some basic code working,then embelish it.