$errmsg =~ /^ # Start of string ( # Start match $1 (?: # Start group (don't save backreference) \[.+?\] # Match set of []'s ){3} # End group and repeat 3 times ) # End match $1 (.*) # Slurp up everything that's left /x; # Done