#!/usr/bin/perl use strict; use warnings; my @files; if ( @ARGV ) { @files = grep { -f } @ARGV; } elsif ( -t ) { # true if STDIN is a tty (not a pipe) die "Usage: $0 file [file2 ...]\n or: ls | $0\n"; } else { # get here when STDIN is connected to a pipe @files = <>; chomp @files; } # ... do stuff with @files #### cat file1 | tool tool file1 tool < file1 cat file1 file2 ... | tool tool file1 file2 ... # (no equivalent using "<" in this case)