my $sthGetFile = $dbh->prepare("select VISUAL,LINK from FILES where (ID=?)"); sub getFile { my ($file) = @_; $sthGetFile->execute($file); return $sthGetFile->fetchrow_arrayref(); }; # Assuming $id exists in the table print getFile($id)->[1];