my $sql = "SELECT * from shop_items"; my $sth = $dbh->prepare($sql); $sth->execute; while (my $hash_ref = $sth->fetchrow_hashref) { # bla bla bla } #### 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; }