The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Text::FindLinks - Find and markup URLs in plain text


    use Text::FindLinks 'markup_links';
    my $text = "Have you seen yet?";
    # Have you seen <a href=""></a> yet?
    print markup_links(text => $text);


markup_links(text => ..., [handler => sub { ... }])

Finds all URLs in the given text and replaces them using the given handler. The handler gets passed three arguments: the URL itself, all the text to the left from it and all the text to the right. (The context is passed in case you would like to keep some URLs untouched.) If no handler is given, the default handler will be used that simply creates a link to the URL and skips URLs already turned into links.

find_links(text => ...)

Returns an array with all the URLs found in given text. Just a simple wrapper around markup_links, see the sources.

decorate_link($url, $left, $right)

Default URL handler that will be used if you don’t pass your own to the markup_links sub using the handler attribute. It turns an URL into a HTML link and skips URLs that are apparently already links. Not exported.


The algorithm is extremely naive, a simple regex. It is almost certain that some URLs will not be recognized and some things that are not URLs will (to keep the balance). I’d be glad to hear if there is some URL that misbehaves.


Tomáš Znamenáček,


Copyright 2009 Tomáš Znamenáček

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.