#!/usr/local/bin/perl -w use strict; open(FILE, ">/tmp/blah") || die "Can Not Open File\n"; my $oldfh = select(FILE); # $oldfh stores the original filehandle # and FILE becomes the current filehandle # for output for (my $n = 1; $n < 10; $n ++) { # use backticks as noted elsewhere print `ping -c 1 192.168.1.$n`; } select($oldfh); # select the original filehandle, # just for neatness close (FILE);