How to display information of the script while its running?

how to display the messages on screen IN PERL such as "

  1. Entering while loop" if the script enters a while loop.

  2. Checking FILENAME. etc...

  3. Print statement is also not helpful....

You mean like debugging information, which prints lines as it runs code without needing print statements? Try the Perl Debugger perl -d scriptname

It's a bit more complicated than set -x since it's an interactive debugger, but not that complicated. The s command tells it to run the next line, and you can repeat that command by holding down enter. q quits.

See man perldebtut for more complete instructions.