push(@last, $1) && last if /(\w+)\.bld$/; #or if you want 'three.bld' in the push: push(@last, $1) && last if /(\w+\.bld)$/;