while(my $hash_ref = fetch_data("SELECT * FROM shop_items")) { # bla bla bla } # SUBROUTINE FOR ALL CALLS sub fetch_data { my $sql = @_; my $sth = $dbh->prepare($sql); $sth->execute; }