#!/usr/bin/perl use strict; use warnings; while () { my $line = $_; chomp $line; my @chunks = unpack "(A5)*", $line; print @chunks . "\n"; # beware, the last 'entry' in chunks is empty, note the < and >! foreach my $i (@chunks) { print ">" . $i . "<\n"; } } __DATA__ a(b)cd(e)fg(h)i j(k)lm(n)o