use strict; use warnings; my $log = parse_regex( q#(\\.|["']|x)# ); print $log; sub parse_regex { my ($regex) = @_; # Catch and stash warnings my $parselog = ''; local $SIG{__WARN__} = sub { $parselog .= $_ for @_; }; # --- compile regex eval q{ use re 'debug'; qr/$regex/; }; return $parselog; }