#!/bin/perl -w use strict; while( ) { chomp; next if(^\s*#); # skip comments # split the data into the string to match and the expected result(s) my( $string, @expected)= split /\s*=>\s*/; while( $string=~ m{/\* # the delimiter ([^*]* # anything but the beginning of the delimiter (?:\*(?!>/) # the beginning of the delimiter, not preceeding the rest of the delimiter # (?!>/) means "not before /, do not use the next char) [^/]* # anything but the beginning of the delimiter )*) # repeat \*/}gx) # the end of the delimiter { my $match= $1; my $expected= shift @expected || ''; unless( $match eq $expected) { print "unexpected result line $.: found /$match/, expecting /$expected/\n"; } } } __DATA__ # string => result(s) toto => toto /*foo*/ tata => foo /*foo*/ tata => foo toto /*foo*/ => foo toto /*foo*bar*/ => foo*bar toto /*foo**/ => foo* toto /**/ => /***/ => * /*/*/ => /