#!/usr/bin/perl use strict; $/ = undef; # go into "slurp" mode $_ = <>; # read whole file at once # (this assumes the file name is given in @ARGV) my @chars = split //; # each array element holds on character my $nlf = grep /\x0a/, @chars; my $ncr = grep /\x0d/, @chars; printf( "Input contained %d characters, %d line-feeds, %d carriage-returns\n", scalar @chars, $nlf, $ncr );