in reply to Files in a directory

I always prefer regexes, but have to admit that choroba's proposal is much cleaner.

use strict; use warnings; my $filename = "p_abc_xyz_123.txt"; print "$1$2$3\n" while( $filename =~ s/(.*)(_\w{3})(\..*)/$1$3/ );