myscript some.data > output # or grep -h foo *.data | sort -u | myscript > output #### binmode STDIN, ":utf8"; #### #!/usr/bin/perl binmode STDIN, ":utf8"; # covers pipe input binmode ARGV, ":utf8"; # does not work -- handle isn't open yet while (<>) { do_whatever( $_ ) } #### #!/usr/bin/perl use strict; my @files; if ( @ARGV ) { @files = @ARGV; } elsif ( -t ) { die "I want file names to open, or else pipeline input"; } else { @files = "stdin"; } for my $file ( @files ) { my $fh; if ( @ARGV ) { open $fh, "<:utf8", $file; } else { binmode STDIN, ":utf8"; $fh = \*STDIN; } while (<$fh>) { do_whatever( $_ ) } }