... while () { if (/^.*?

.*?( $sw )/) { # first if ... if ( $dec eq "y" ) { # second if ... } else { ## NOW else is attached to the second if, and now works as intended ... } } ## END of first if statement. ...