#!/usr/bin/perl -wT use strict; %ENV = (PATH => '/bin:/usr/bin'); # give us a happy enviornment my $filename = '/etc/services'; # filename to be checked my $length = do { my $string = `wc -l $filename`; # get output of wc die "wc error $?" if $?; # die if wc chokes for some reason no warnings 'numeric'; # turn off a pesky warning ;-) $string + 0; # numerify it with +0 }; print "length = $length\n"; # "length = 331" on my machine #### ($string =~ /\d+/g)[0]; #### my $length = (`wc -l $filename` =~ /\d+/g)[0]; # get output of wc die "wc error $?" if $?; # die if wc chokes for some reason