in reply to separating two sententences
When you say "doesn't work" it tells us nothing. Try telling us what your expected output and actual output were.
For starters, I would add:
to your script make coding errors more obvious. and I would hazard a guess that you are not opening the file properly. checking the return code of the open would find that:
open IN,"<","file" or die "error opening file: $!";
"Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."