#! /usr/local/bin/perl -w use Regexp::Assemble; my $ra = Regexp::Assemble->new->add( 'Error 123 on SystemA file not found error', 'Error 123 on SystemB file not found error', 'Error 123 on SystemC file not found error' ); print $ra->re; #### (?-xism:Error 123 on System[ABC] file not found error) #### #! /usr/local/bin/perl -w use Regexp::Assemble; my $ra = Regexp::Assemble->new->add( 'Error 124 on User1:FileA no space left', 'Error 124 on User2:FileB no space left', 'Error 124 on User3:FileC no space left' ); print $ra->re; #### (?-xism:Error 124 on User(?:1:FileA|2:FileB|3:FileC) no space left)