#!/usr/bin/perl -w use strict; use XML::Twig; use Test::More tests => 1; $/="\n\n"; (my $input= )=~ s{\\t}{\t}g; # I used \t in the DATA section to avoid problems (my $expected_output= )=~ s{\n\s*}{}g; # remove extra formating my $t= XML::Twig->new( pretty_print => 'indented') ->parse( $input); $t->root->mark( qr/^\n*(.*)\t/s, 'first'); # wrap text before a tab $t->root->wrap_children( '' => 'second') # wrap remaining abc children ->strip_att( 'id'); # strip extra id added by wrap_children (my $output= $t->sprint)=~ s{\n\s*}{}g; ok( $output eq $expected_output); __DATA__ abc\t

ahgkslkjs

hai

abc\t

ahgkslkjs

abc

ahgkslkjs

hai

abc

ahgkslkjs