use constant BLANK_LINE => qr{ \A \s* \z }xms; use constant EMPTY_R_PAIR => "\n"; ... $out = EMPTY_R_PAIR if $out =~ BLANK_LINE;