#!/usr/bin/env perl use strict; use warnings; my $wanted_sub = 'Subroutine2'; my $pod_string; { local $/ = "\n=head1 "; while () { if (/\A $wanted_sub $/mx) { ($pod_string = $_) =~ s/\A .+? ^ ( .+? ) =cut .* \z/$1/msx; last; } } } print $pod_string; __DATA__ package MyModule; =head1 Subroutine1 My POD for Subroutine1 =cut sub Subroutine1 { ... ... } =head1 Subroutine2 My POD for Subroutine2 =head2 Dummy Heading 2 =over 4 =item whatever qwerty =item blah asdfgh =back Some text =cut sub Subroutine2 { ... ... } 1;