if ($msg =~ /^Error while copying (.*) from (.*) to (.*), error was/) { my ($filename, $source_dir, $dest_dir) = ($1, $2, $3); ... do something ... }