some_script.pl file1 file2 #### In a "while (<>)" loop, "eof" or "eof(ARGV)" can be used to detect the end of each file, "eof()" will only detect the end of the last file. Examples: ... #### my $prefix = 1; while (<>) { print "$prefix: $_"; $prefix++ if ( eof ); } #### cat file1 file2 | some_script.pl # or something less mundane: grep "target string" file1 | cat - file2 | some_script.pl #### echo "____STREAM_BOUNDARY____" > bndry grep "target string" file1 | cat - bndry file2 | script.pl