use strict; use warnings; use utf8; use Test::More tests => 3; for my $line() { chomp $line; my ($string, $wanted) = split '#', $line; $string =~ s/^(\d+)\s*[–-](.*)/$1.$2/; is $string, $wanted; } __END__ 1234 - Foo#1234. Foo 56778 – Bar#56778. Bar 9999. Baz#9999. Baz