perl -i.old -lne 'BEGIN { $sshport = pop }; print unless /^[\s#]*Port/i; END { print "Port $sshport" }' sshd_config 1234