#!/usr/bin/perl use 5.010; use strict; use warnings; my $string = 'abc123def456'; chomp( my $input = ); eval { if( $string =~ m/\Q$input\E/p ) { say ${^MATCH}; } }; warn $@ if $@;