foreach $day ($doc->findnodes('/my/current/path')){ @atts = $day -> getAttributes(); foreach $at (@atts) { $na = $at -> getName(); $va = $at -> getValue(); if ($va eq "today"){ #------ my repeated code here ----- foreach $thing ($day->findnodes('child_nodes_im_looking_for')){ #----- do a lot of stuff } } if ($va eq "tomorrow"){ #same repeated code } if ($va eq "some_other_day"){ #same repeated code.... again } #for other days... do nothing }