use warnings; use strict; use Test::More tests=>4; my $str = "##############################################################################\r\n# This system is a restricted access system. #\r\n# If collected security information reveals possible criminal activity that #\r\n# exceeds privileges, evidence of such activity may be provided to the rele- #\r\n# vant authorities for further action. By continuing past this point, you #\r\n# expressly consent to this security monitoring. #\r\n##############################################################################\r\n\r\nhostname: ~# "; my $re1 = qr{(([#%:>~\$\] ])(?!\2)){3,4}|([\w\-\.]*)\$ *$|\w[@\/]\w.*?[#%>~\$\]]|^[#%\$>\:]~] *$}; my $re2 = qr{(([#%:>~\$\] ])(?!\2)){3,4}|([\w\-\.]*)\$ *$|(\w[@\/]\w|sftp).*?[#%>~\$\]]|^[#%\$>\:]~] *$}; ok $str =~ $re1; is $&, ": ~#"; ok $str =~ $re2; is $&, ": ~#";