my @nasties = ( 'foo and exit', "foo\nand\nexit\n", "hello", "foo\000exit", ); for my $layer(@nasties) { print $layer =~ m/^([\w:]+)$/ ? "OK $layer\n" : "ERR $layer\n"; }