#!/usr/bin/perl use strict; use warnings; while() { /^#/ and next; chomp; if ( m{ <([^>]*?)> [^<]*? }x ) { while ( m{ <([^>]*?)> [^<]*? }gx ) { my $token = $1; # Some verbose info. Note first line doesn't # get printed because it doesn't match regex print $_, "\n"; print "Found <$token> and , removing...\n"; s{<$token>}{}g; s{}{}g; } } else { # search engine while ( m{ ]*?)> }x ) { my $close = $1; if ( m{ <($close[^>]*?)> [^<]*? }x ) { my $open = $1; print $_,"\n"; print "Found <$open> and , removing\n"; s{<$open>}{}g; s{}{}g; print $_,"\n"; } } } # Of course, this will be hard to do if you # "don't know how many dashes, if any, will # be there." print "\t$_\n" for ( split (/-- /,$_) ); print "\n"; } __DATA__ This is a -- string of -- words This is a -- string of -- words This is a -- string of -- words This is a -- string of -- words This is a -- nested set of -- tokens This is -- an awesome -- search engine Truly an -- ugly -- nested st ring #This string -- causes -- my box to hang