#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11143647 use warnings; while (my $x = ) { chomp $x; print "\n$x\n"; my $out = ''; while ( $x =~ m/ ([[:punct:]]*) # $1: leading punct marks ( # $2: a "word" consisting of [[:word:]]+ # word (?: (?: '-? | - ) [[:word:]]+ # and ending in pure word characters )* ) ( (?: --+ | [[:punct:]]* ) \ ? ) # $3: trailing punct marks ending # or multi-dashs # with space (except at end of # line?) /xxg ) { $out .= sprintf "{%s|%s|%s} ", # make whitespace visible map {(my $y = $_ // '') =~ tr/ /_/; $y} $1, $2, $3; } print "$out\n" =~ s/ $//r =~ s/.{65}\K /\n/gr; } __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?"