Using eof and <> together.
#!/usr/local/bin/perl while ($line = <>) { print ($line); if (eof) { print ("-- end of current file --\n"); } } while ($line = <>) { print ($line); if (eof()) { print ("-- end of output --\n"); } }