# you already have this part: my $qry_file = "some_name.sql"; # or whatever open( QRY, ">$qry_file" ) or die "can't write $qry_file: $!"; print QRY "select foo from bar where baz='x'\n"; close QRY; # Run isql by opening it as a pipeline # (I'm guessing at the command-line usage): my @fnames, @lnames; # query output will be stored here # update: using the correct variable name for the query file: open( DB, "isql $qry_file |" ) or die "can't run isql: $!"; while () { # assuming the tool prints one line per row chomp; # remove newline my ( $lname, $fname ) = split(/\t/); # assuming fields are tab-delimited push @fnames, $fname; push @lnames, $lname; } close DB; # now you can do whatever you want, iterating over # the contents of @lnames and/or @fnames for my $i ( 0..$#fnames ) { print "Row = $i, Full_name = $fnames[$i] $lnames[i]\n"; }