Run Perl code from any Ruby application, or run Perl web apps on Ruby.
Ruby Perl
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Ruby and Perl, sitting in a tree K-I-S-S-I-N-G

For rubyists:

ruby-perl lets you evaluate and run Perl code within the same binary, without any heavy-weight forking of sub-processes. Enjoy the compactness, robustness and maintainability of Perl!

For perlists:

Run your Perl application over industry-standard, enterprise-grade MRI Ruby, Rack and Passenger!

Background story

Check out our announce blog post for the story behind this.

Getting started

On the command line

Install the gem:

gem install ruby-perl

Run a Perl program:

rperl examples/

Or play around in the Perl interactive shell:

rperl -de 0

Web applications

You can run your Perl webapp with Rack using the provided Rack adapter:

thin -R examples/

ruby-perl supports PSGI (Perl Web Server Gateway Interface Specification); as such it can run any webapp written in any conforming framework, such as Mason.

However, for the time you have to provide your own Rackup file. Luckily a typical Rackup file for ruby-perl is fairly simple (just take a look at examples/ in the repository), and it boils down to:


ruby-perl has been developed with Thin in mind, but since Phusion Passenger is 100% compatible with Rack, you can use it too: just stick a file in your document root (together with the mandatory public/ and tmp/ subdirectories) and you are ready to go. Read The Fine Passenger Manual for more info.

In your own application: evaluating Perl code

You can embed Perl code directly in your Ruby application in a nice and friendly way:

require 'perl'

def foo(arg) %Q{$_=#{arg};(1x$_)!~/^1?$|^(11+?)\\1+$/&&print"$_\n"}


For additional eye-candy, more styles are supported:

Perl <<-PERL
  return 0 if $_[0] =~ 
  return 1 if $_[0] =~ 
  return 0;


Perl do
  run <<-PERL
    my @sorted_ips = #sort by ip
      map substr($_, 4) =>
        sort map pack('C4' =>
          split /\./)
            . $_ => (@unsorted_ips);

Embedded Perl however has a some pretty big limitation, the biggest being that you cannot easily pass data from Ruby to Perl and vice-versa, except by string interpolation as shown in the first example.

In your own application: invoking Perl code

ruby-perl lets you invoke arbitrary Perl code you have loaded or evaluated. In other words, you can implement some functionality in Perl and seamlessly call it from Ruby:

require 'perl'

Perl do
  @func = eval %Q{sub { $arg = shift; print "You said: $arg\n"; };}
  call @func, "42", :scalar

In the previous snippet we first define a Perl sub and we assign it to the @func instance variable; we then call it passing a String. For all intents and purposes, @func is now a lambda you can pass around and call, only it's implemented in Perl.


  • Andrea Campi (@andreacampi)
  • Chris Weyl (@RsrchBoy)

Bug reports

ruby-perl is rather well test with RSpec, however you may still find a few bugs. Please report them any issue you may find.

Copyright and license

Copyright (c) 2011 ZephirWorks. This code is released under the MIT license.