#!/usr/bin/perl use warnings; use strict; use constant { WORD => 0, TYPE => 1, }; my @annotations; while () { my ($word, $type) = split; $type =~ s/.-*//; push @annotations, [ $word, $type ]; } print ''; print join ' ', map $_->[WORD], @annotations; print ''; for my $annotation (@annotations) { print ''; print '', $annotation->[TYPE], ''; print '', $annotation->[WORD], ''; print ''; } __DATA__ how B-NP are I-NP you I-NP