http://www.perlmonks.org?node_id=64225


in reply to Counting number of characters in a string

sicker and twisteder!!
use strict; use IPC::Open2; my $pid = open2 (\*RDRFH, \*WTRFH, '/usr/bin/wc', '-c') or die "Couldn't open pipe to wc: $!"; if ($pid) { my $string = "shoes and ships and sealing wax"; print WTRFH $string; close (WTRFH); my $len = <RDRFH>; $len =~ s/^\s+//; print "length: $len"; close (RDRFH); }