my $sshport; while ( $sshport !~ /^[1-9]\d+$/ || $sshport > 65535 ) { print " Please Enter valid ssh port number:\n"; chomp( $sshport = ); } #### while (){ s/^Port.+/Port $sshport/i; s/^#Port\s.+/Port $sshport/i; print SSHD_CONFIG_NEW $_; } #### rename('sshd_config','sshd_config.old') or die "Can't rename sshd_config: $!"; rename('sshd_config.new','sshd_config') or die "Can't rename sshd_config.new: $!";