How do I match a pattern that is supplied by the user?

Well, if it's really a pattern, then just use

    chomp($pattern = <STDIN>);
    if ($line =~ /$pattern/) { }
Alternatively, since you have no guarantee that your user entered a valid regular expression, trap the exception this way:

    if (eval { $line =~ /$pattern/ }) { }
If all you really want to search for a string, not a pattern, then you should either use the index() function, which is made for string searching, or if you can't be disabused of using a pattern match on a non-pattern, then be sure to use \Q...\E, documented in perlre.

    $pattern = <STDIN>;
    open (FILE, $input) or die "Couldn't open input $input: $!; aborting";
    while (<FILE>) {
	print if /\Q$pattern\E/;
    }
    close FILE;

Back to perlfaq6