#!/usr/bin/env perl use 5.010; use warnings; use strict; my $n; # line no while (my $x = ) { chomp $x; say $x; while ( $x =~ m/ ([[:punct:]]*) # $1: leading punct marks ( # $2: a "word" consisting of (?: [[:word:]']+ - )* # optional segments with # embedded {'}s ending with # single {-} [[:word:]]+ # and ending in pure word characters ) ([[:punct:]]* \ ? ) # $3: trailing punct marks ending # with space (except at end of # line?) /xxg ) { printf " %3s {%s|%s|%s}\n", ++$n, # make whitespace visible map {(my $y = $_ // '') =~ tr/ /_/; $y} $1, $2, $3; } } __DATA__ "'Uncouth' about sums it up." The word they will use is 'uncouth'. "It's the old story." It's a will-o'-the-wisp--a two-fer--and Bob's-yer-uncle at four o'clock. It's two o'clock--time for a nap. Remember 45's? What about (this)? [Editor's note: blah blah] and so on... A ... and B I said--"What's the expression?"