making code more perl idiomatic