my $sock = new IO::Socket::INET( PeerAddr => $host, PeerPort => $port, Proto => "tcp",) or die "Cannot connect to PBX on address $host port $port: $!"; while (<$sock>) { print; # print to screen as well to show raw data and connection chomp($_); open(DAT,">>$filename") || die("Cannot open smdr file"); print DAT $_; close(DAT);