Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

60%
+1 −0
Challenges Abbreviate everything

Perl, 62 bytes Reads a line from stdin. Prints abbreviation to stdout. perl -pe'y/ .!?/! /s;s/[^:;a-z ]*([a-z])[^:;! ]*!?| $/\u$1/gi' convert .!? to space and space to ! then squeeze dupl...

posted 6mo ago by jhnc‭  ·  edited 6mo ago by jhnc‭

Answer
#2: Post edited by user avatar jhnc‭ · 2026-03-21T08:38:18Z (6 months ago)
  • # Perl, 62 bytes
  • Reads a line from stdin. Prints abbreviation to stdout.
  • ```
  • perl -pe'y/ .!?/! /s;s/[^:;a-z ]*([a-z])[^:;! ]*!?| $/\u$1/gi'
  • ```
  • * convert `.!?` to space and space to `!`
  • * then squeeze duplicate runs
  • * perform case-insensitive substitutions
  • * consume everything up to `!` (or EOL)
  • * replace with the first letter as uppercase
  • * OR discard trailing space
  • [Try it online!][TIO-mn01u3vz]
  • [TIO-mn01u3vz]: https://tio.run/##FY29asMwFEZ3PcUnCPQH26JDh9SDhgxp9kKGNAW5uo1FFV0hyRiXPnvVeDqcs5xIyT/Xuih0UisJlfusTh8vvWl/cH68P914fliDvKnUv9io92nzpC6u1lfynhscOXkrxc4ELDzhar4JV4JBNsHO7nPUYlwipTbQVJILLN6Y4Tlcelhnw11BImPFAblM1pFtYHmtM6e0dDhgdt4jmpw7cRxN0VpLLcWeyvrZbjFwKZ4y@AsDUWowJJbij2NxHHJto/8H "Perl 5 – Try It Online"
  • # Perl, 62 bytes
  • Reads a line from stdin. Prints abbreviation to stdout.
  • ```
  • perl -pe'y/ .!?/! /s;s/[^:;a-z ]*([a-z])[^:;! ]*!?| $/\u$1/gi'
  • ```
  • * convert `.!?` to space and space to `!`
  • * then squeeze duplicate runs
  • * perform case-insensitive substitutions
  • * don't touch `:`, `;` or space
  • * OR consume everything up to `!` (or EOL)
  • * then replace with the first letter as uppercase
  • * OR discard trailing space
  • [Try it online!][TIO-mn01u3vz]
  • [TIO-mn01u3vz]: https://tio.run/##FY29asMwFEZ3PcUnCPQH26JDh9SDhgxp9kKGNAW5uo1FFV0hyRiXPnvVeDqcs5xIyT/Xuih0UisJlfusTh8vvWl/cH68P914fliDvKnUv9io92nzpC6u1lfynhscOXkrxc4ELDzhar4JV4JBNsHO7nPUYlwipTbQVJILLN6Y4Tlcelhnw11BImPFAblM1pFtYHmtM6e0dDhgdt4jmpw7cRxN0VpLLcWeyvrZbjFwKZ4y@AsDUWowJJbij2NxHHJto/8H "Perl 5 – Try It Online"
#1: Initial revision by user avatar jhnc‭ · 2026-03-21T08:14:58Z (6 months ago)
# Perl, 62 bytes

Reads a line from stdin. Prints abbreviation to stdout.

```
perl -pe'y/ .!?/! /s;s/[^:;a-z ]*([a-z])[^:;! ]*!?| $/\u$1/gi'
```

* convert `.!?` to space and space to `!`
  * then squeeze duplicate runs
* perform case-insensitive substitutions
  * consume everything up to `!` (or EOL)
    * replace with the first letter as uppercase
  * OR discard trailing space


[Try it online!][TIO-mn01u3vz]

[TIO-mn01u3vz]: https://tio.run/##FY29asMwFEZ3PcUnCPQH26JDh9SDhgxp9kKGNAW5uo1FFV0hyRiXPnvVeDqcs5xIyT/Xuih0UisJlfusTh8vvWl/cH68P914fliDvKnUv9io92nzpC6u1lfynhscOXkrxc4ELDzhar4JV4JBNsHO7nPUYlwipTbQVJILLN6Y4Tlcelhnw11BImPFAblM1pFtYHmtM6e0dDhgdt4jmpw7cRxN0VpLLcWeyvrZbjFwKZ4y@AsDUWowJJbij2NxHHJto/8H "Perl 5 – Try It Online"