#!/usr/bin/perl -w use strict; use warnings; my @newtokens; push @newtokens,'foo'; my @tags; push @tags,'bar'; foreach $token (@newtokens) { $token =~ s/\@\@\@\@ ~~~~/ /sig; foreach $tag (@tags) { $token =~ s/~~~~(\/*.*?)\@\@\@\@/<$1>/sig; } }