#!/usr/local/bin/perl -w # use strict; # Make some building blocks. What we want at the start; what we don't want # after "foobar:" using a negative look-ahead assertion; any five # characters; what we want at the end (which we will discard later). # our $rxFooBar = qr{foobar:}; our $rxNotGonkish = qr{(?!(?:g(?:o(?:n(?:k)*)*)*|@))}; our $rxFive = qr{.{1,5}}; our $rxGonk = qr{(?:gonk|@)}; # Put the building blocks together using "()" to capture everything except # the "gonk" or "@" at the end; # our $rxPutItAllTogether = qr{($rxFooBar$rxNotGonkish$rxFive)$rxGonk}; while() { chomp; print "$_\n"; print /$rxPutItAllTogether/ ? "$1\n\n" : "Failed\n\n"; } __END__ foobar:hellogonk foobar:gonk foobar:higonk foobar:helloworldgonk foobar:ggonk foobar:gogonk foobar:gongonk foobar:gonkgonk foobar:gonkygonk foobar:@gonk foobar:its@ foobar:toomany@