#!/usr/bin/env perl use strict; use warnings; use Test::More; my @set = ( { in => 'ABCDEFGHI', want => "ABCD\nEFGH\nI\n" }, { in => 'ABCDEFGHI', want => "ABCD\nEFGH\nI\n" }, ); plan tests => scalar @set; my $len = 4; for my $x (@set) { my $i = 0; my $out = ''; my $intag = 0; for my $c (split (//, $x->{in})) { $out .= $c; $intag++ if $c eq '<'; $intag-- if $c eq '>'; next if $intag || $c eq '>'; $i++; $out .= "\n" unless $i % $len; } $out .= "\n"; is ($out, $x->{want}); }