#!/usr/bin/perl use strict; use warnings; while() { chomp; while ( m{ <([^>]*?)> [^<]*? }gx ) { my $token = $1; s{<$token>}{}g; s{}{}g; } # 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 -- a nifty -- search engine