<> is a file descriptor reading operation and it is already inside the script, so you should run either perl script.pl mytext.txt >output.txt (passing filename as command line argument) or perl script.pl <mytext.txt >output.txt (passing file contents as STDIN).